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
Titre:
Copying an Object - avoiding single object references
Divers
Thread ID:
00365455
Message ID:
00365455
Vues:
41
I have a problem that maybe one of you has an idea on.

This is inside of Web Connection for parsing XML into array properties which contain a set of objects. The logic to create and parse the objects into array properties works fine.

But I'm unable to create these array objects in such a way that they are all unique - what happens at the moment is that a single reference is copied causing all items to point at the sae reference resulting in all of the elements having the same values.

This doesn't work correctly, because of the fact that an object assigned to a variable is always a reference to another object.

The problem here is that I can't instantiate the object - I have to use whatever the user passes in, which is a preinitialized object assigned in the first element of the array. In order Web Connection for WC to parse objects it needs to know the structure of the object which must be provided in the first element of the arary that is to be filled from XML.

I have some code that does this with the array:

lvValue = laArray[1] && This will contain the object 'blue print'
lcType = VARTYPE(lcValue)

IF lcType = 'O'
DIMENSION laArray[lnRows]
FOR x = 1 to lnRows
laArray[x] = lvValue && assign all properties
ENDFOR
ENDIF
lvValue = .F. && Delete the 'common' reference

This works to initialize each of the array members with an object which can then be passed to parsexmltoobject.

However, the problem above is: All of the array elements are basically pointing at the same object reference. Change one, you're changing them all.

Anybody see a way of being able to create an array of objects that essentially contain a copy of the original object?

The easy answers don't work in this scenario: Using the .Class property to create a new instance (some objects such SCATTER NAME don't have a Class member, nor would the properties contain the proper typed values, nor would nested subobjects or arrays be there).

Anybody have any ideas?
+++ 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?
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform