>
>Object1 = CreateObject("Custom")
>Object1.AddProperyt("Test", "Green")
>Object 2 = Object1
>Object2.Test = "Red"
>?Object1.Test
>
>Object 2 = Object1
>
>
>How can I make an independant copy of Object1?
Only at design time, using obj.CloneObject("newname") in a builder. I've done a bunch of builders and never used this... just didn't find it useful.
I know it's not polite to ask "what do you need this for", because you probably have good reasons, but since creating a copy of an object is such a pain downstairs, we may help you achieve what you want by different means.
To copy an object you basically create another of the same class and classlib, then start copying any properties of the first object that are different from default. Amembers(aArray, oFirstObj,0, "C") would give you the list... something like this:
procedure copyobject(oObj, lcNewObjName)
loNewObj=newobject(oobj.class, oobj.classlibrary)
loNewObj.name=lcNewObjName
n=Amembers(aArray, oObj,0, "C")
for i=1 to n
lonewobj.addproperty(aArray[i], getpem(oObj, aArray[i]))
endfor
return loNewObj
The problem with this is that some of the properties need to be skipped - for instance, they may be read-only, or protected, or hidden. Then, there's also the matter of the object's parent - do you want them to be child objects of the same parent? In that case, lines 2 and 3 are replaced with
oObj.parent.newobject(lcNewObjName, oobj.class, oobj.classlibrary)
and you may need to skip the name property in your loop.
Another problem here is what would you do if your object is a composite object - an optiongroup, a grid, a container...? Wouldn't you have to recurse and copy the member objects as well? And check for their readonly, protected etc properties?
So... I figure object copying is feasible, but it's so riddled with problems and trouble, that it's probably not worth it - there is usually a simpler way to do whatever you wanted to accomplish.