Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Copying an Object - avoiding single object references
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00365455
Message ID:
00366869
Vues:
14
Thanks for all of your feedback folks...

After a little mroe consideration I decided to break down and use a code based copy mechanism and it turns out that this code is not terribly inefficient.
* wwxml::copyobject
LPARAMETER oObject
LOCAL loObject, laFields[1], x, lcField, lcType

loObject = CREATE(THIS.cObjectClass)
lnCount = AMEMBERS(laFields, oObject)

FOR x=1 to lnCount
   lcField = LOWER(laFields[x])
   IF AT("," + lcField + ",","'" + THIS.cPropertyExclusionList)>0
       LOOP
   ENDIF
   lcType = TYPE("loObject."+lcField)

   IF lcType = "O"
      loObject.AddProperty(lcField)
      THIS.CopyObject(EVAL("oObject."+lcField))
   ELSE
      loObject.AddProperty(lcField,EVAL("oObject."+lcField))
   ENDIF
ENDFOR

RETURN loObject
This version doesn't do arrays, but in my case I don't need that as I'm using this to deal with object array processing in the first place. Adding array support would just require one extra step of checking for the array and then figuring out the dimensions to walk.

As it is, this will copy the array as a reference so it is available, but if the array contains objects then it's back to square one <s>...

This is pretty cool. wwXML can now import totally hierarchical objects that include object arrays for one to many relationships.
o=CREATE("cInvoice")
o.Load(     849584)

? o.oData.InvTotal
? o.oCustomer.oData.Company
? o.oLineItems.aRows[1].odata.ItemTotal

loXML = CREATE("wwXML")
loXML.lRecurseObjects = .t.
lcXML = loXML.ObjectToXML(o)
ShowXML(lcXML)

RELEASE o

*** Create new Invoice object and restore from XML
o=CREATE("cInvoice")

*** Load a blank invoice with empty customer
*** and lineitems objects
o.Load(0)

loXML = CREATE("wwXML")
loXML.lRecurseObjects = .t.
loXML.XMLToObject(lcXML,o)

*** Shows Data restored from XML
? o.oData.InvTotal
? o.oCustomer.oData.Company
? o.oLineItems.aRows[1].odata.ItemTotal
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform