Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems with collections
Message
De
21/10/2008 22:35:01
 
 
À
21/10/2008 22:30:47
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01356180
Message ID:
01356195
Vues:
24
Dragan --

However, as I noted, I specifically don't want an object reference. What I want is to make a copy of all the values in the collection so that later I can compare those values to the current values. Saving an object reference ... means the two are always identical.



>>I'm having problems working with Collections (not surprisingly, since this is my very first time creating a collection).
>>
>>I have a form with a collection named .Fields .... This.Fields (I've inherited this from somebody else). Each item in This.Fields is an object with the same simple list of properties.
>>
>>I want to copy the entire collection into an object I've created called loProperties. Now, I don't want to copy an object reference, since my goal is to later compare the values in This.Fields with loProperties.Fields. to see which have changed.
>>
>>My code to do this follows. When done, however, loProperties.Fields(1) does not have the same list of properties as This.Fields(1) --- it actually looks like a collection itself.
>>
>>Can anybody identify what I'm doing wrong here? (Note: loFields looks like the collection I would expect ... but loProperties.Fields doesn't)
>
>You seem to want to copy members from one collection to another, with properties, eh? Assuming you tried the obvious (setting loFields=this.fields, or adding references to members of this.fields to loFields) and you really have to clone each object, then... see what I'd rather do: have a reference to the object you're copying. Makes debugging easier. Also, getpem() is easier than eval().
>
>>
	loFields = Createobject("Collection")
>>	For lnJ = 1 To This.Fields.Count
>>		m.loData = Createobject("Empty")
>   loSourceObject=This.Fields.item(lnJ)
>>		Amembers(laFieldMembers, loSourceObject)
>>		For Each lcFieldMem In laFieldMembers)
>>			AddProperty(m.loData, lcFieldMem, getpem(loSourceObject, lcFieldMem))
>>		Endfor
>>
>>		loFields.Add(m.loData)
>>	Next lnJ
>>	AddProperty (loProperties, 'Fields', loFields)
>>
Jim Nelson
Newbury Park, CA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform