>Hi James,
>
>>Is there some easy way to copy an object? Like ACOPY() but for objects? Simple assignment creates a reference to the object rather than an new instantiantion.
>
>Depends. If you like to do this at Design time for objects in the Class Designer, you can use the CloneObject() method. At runtime there's no built in way. The easiest way would be to make every object aware of that it can be duplicated and create a method CopyObject() that returns a fully initialized object:
>
> Procedure CopyObject
> Local loObject
> loObject = CreateObject(This.Class)
> loObject.SetProperties( This )
> Return loObject
>
> Procedure SetProperties
> LParameter toSource
> This.Property1 = toSource.Property1
> This.Property2 = toSource.Property2
> * etc.
> EndProc
>Christof
That's what I ended up doing because CloneObject does not work for custom classes. It's not so simple because one has to consider child objects of the object you want to copy. (I didn't bother with the function below) And the init clause of the object. Probably some clever person has alreeady written something that does it. But maybe not! I haven't needed it until today so it can't be sooo dringend.
Thankyall for the input!
James
FUNCTION GetCopy()
m.loCopy = CREATEOBJECT(THIS.Class,THIS.oSession)
&& Get list of properties
AMEMBERS(laFilter,m.loCopy,1)
&& Go through list of properties
FOR m.i = 1 TO ALEN(laFilter,1)
IF PROPER(laFilter(m.i,2)) # 'Property'
LOOP
ENDIF
&& User Defined only
IF NOT PEMSTATUS(m.loCopy,laFilter(m.i,1),4)
LOOP
ENDIF
lcGETProperty = [m.loCopy.]+laFilter(m.i,1) + [ = THIS.] +laFilter(m.i,1)
&& Assign Property
&lcGETProperty
ENDFOR &&* m.i = 1 TO ALEN(laFilter,1)
RETURN m.loCopy
ENDFUNC &&* GetCopy
James Beerbower
James Beerbower Enterprises
Frankfurt, Deutschland