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:
00365961
Vues:
14
Hi Rick,

I am not sure I get what you are presenting here (probably cause it's after midnight here < g >). Could you give a small sample of XML and show the array in a way that makes the problem clearer?

If I understand, you are creating an array of tag object objects and value properties, each of which (depending on the hierarchy) have an array of tag object objects and value properties.
< customer id=1 >
  < NAME > Rick H < /NAME >
  < ADDRESS > 
     < STATE > Confused < /STATE >
     < ZIP > 11111 < /ZIP >
  < /ADDRESS >

< /customer >
< customer id=2 >
  < NAME > Rick S < /NAME >
  < ADDRESS > 
     < STATE > HAWAII < /STATE >
     < ZIP > 77777 < /ZIP >
  < /ADDRESS >

< /customer >

{root object}
array[1] = {customer object (id=1)}
array[2] = {customer object (id=2)}

{customer object (id=1)}
array[1] = "1"  (id value)
array[2] = {Name object (id=1)}
array[3] = {Address object (id=1)}

{name object id=1}
array[1] = "Rick H" (value in name tag)

{address object id=1}
array[1] = {State Object}
array[2] = {Zip Object}

{state object id=1}
array[1] = "Confused" (value in state tag)

{zip object id=1}
array[1] = "11111" (value in zip tag)

{customer object (id=2)}
array[1] = "2"  (id value)
array[2] = {Name object (id=2)}
array[3] = {Address object (id=2)}

{name object id=2}
array[1] = "Rick S" (value in name tag)

{address object id=2}
array[1] = {State Object (id=2)}
array[2] = {Zip Object (id=2)}

{state object id=2}
array[1] = "HAWAII" (value in state tag)

{zip object id=2}
array[1] = "77777" (value in zip tag)
I ommitted a column for property name for sake of brevity: e.g.
array[1,1]="Name"
array[1,2]={Name object}
Am I close?

Rick

>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 Hodder
MCP Visual Foxpro
C#, VB.NET Developer
Independent Consultant
www.RickHodder.com
MyBlog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform