Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Serializing / unserializing recursive objects
Message
De
11/08/2005 04:19:33
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01035740
Message ID:
01040106
Vues:
21
>No collections are supported, just not at the root.

But once again, in my example the root object is not a collection, it just contains a collection at level 1.
I wrapped my previous example in a new class, so that the collection would now be at level 2. I still get the error "Member GETNAMEDITEM does not evaluate to an object".
But the same example seems to work when the collection consists of strings instead of objects, except that the collection in the recreated object then contains both the preset value and the imported value (while I would expect it to contain only the imported value).
Can the import of a collection of objects really work ?

My new example :
DEFINE CLASS MyWrapper AS Custom
	oMyCollection=null
	FUNCTION INIT
		THIS.oMyCollection=CREATEOBJECT("MyCollection")
	ENDFUNC
	FUNCTION ToString
		RETURN THIS.oMyCollection.ToString()
	ENDFUNC
ENDDEFINE

DEFINE CLASS MyCollection AS Custom
	oCollection=null
	nOtherMember=1
	FUNCTION INIT
		THIS.oCollection=CREATEOBJECT("Collection")
	ENDFUNC
	FUNCTION ToString
		LOCAL lcResult, loNumber
		lcResult=""
		FOR EACH loNumber IN THIS.oCollection
			lcResult=lcResult+loNumber.ToString()+";"
		ENDFOR
                RETURN lcResult
	ENDFUNC
ENDDEFINE

DEFINE CLASS MyNumber AS Custom
	nNumber=0
	FUNCTION INIT
	LPARAMETERS nNumber
		THIS.nNumber=nNumber
	ENDFUNC
	FUNCTION ToString
		RETURN ALLTRIM(STR(THIS.nNumber))
	ENDFUNC
ENDDEFINE
SET PROCEDURE TO wwUtils.prg, basic_objects.prg
SET CLASSLIB TO ../classlib/wwxml.vcx
LOCAL loXml, loColl, loColl2, loNumber, loNumber2, lcXml
loXml=CREATEOBJECT("wwxml")
loXml.lRecurseObjects=.T.
loW1=CREATEOBJECT("MyWrapper")
loW2=CREATEOBJECT("MyWrapper")
loNumber=CREATEOBJECT("MyNumber",1)
loNumber2=CREATEOBJECT("MyNumber",2)
loW1.oMyCollection.oCollection.Add(loNumber)
loW2.oMyCollection.oCollection.Add(loNumber2)
lcXml=loXml.ObjectToXml(loW1)
loXml.XmlToObject(lcXml,loW2)
? loW2.ToString()
Greetings,

David
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform