Hi Alan,

Your solution works fine for objects having their properties as in the class

OP was asking for cloning object with modified properties.

I'm not sure what DoCopy(loMyCopy) effectively does.

Thierry Nivelet
FoxInCloud
Give your VFP app a second life in the cloud
http://foxincloud.com/

Le 26/06/14 12:25, Alan Bourke a écrit :
The easiest way to create a deep copy of an existing object (as opposed
to just a pointer to the original object) is to leverage the fact that
by default parameters are passed by value in Visual Foxpro. So to make
an copy:

* -- CODE START
* -- Your original object.
loMyObject = CreateObject("MyObject")
loMyObject.Property1="hello"

* -- A new instance to hold the copy.
        loMyCopy = CreateObject("MyObject")
        loMycopy = DoCopy(loMyCopy)

* -- Make an copy.
Function DoCopy(loObjectIn as Object)
Return loObjectIn
* -- CODE END


So then:
? loMyObject.Property1    yields "hello"
? loMyCopy.Property1      yields "hello"
loMyCopy.Property1 = "bonjour"
? loMyObject.Property1    yields "hello"
? loMyCopy.Property1      yields "bonjour"







_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/53ad4e1e.2090...@foxincloud.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to