Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Copy a Object ??
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00258802
Message ID:
00260408
Views:
19
>>x=createobject('form')
>>y=createobject(x.class)
>
>It only creates an object of the same class, not a copy of the initial object.

Try this.
John Burton

FUNCTION CopyObjectProperties
LPARAMETERS oSource, oTarget
LOCAL aProperties[1], i, p1
DO ListCustomProperties WITH oSource, aProperties
FOR i = 1 TO ALEN(aProperties)
p1 = aProperties[i]
IF TYPE('oTarget.&p1[1]')='U'
* not an array
oTarget.&p1 = oSource.&p1
ELSE
= ACOPY(oSource.&p1, oTarget.&p1)
ENDIF
ENDFOR
ENDFUNC

PROCEDURE ListCustomProperties
LPARAMETER oObject, aArr
LOCAL a1[1], a2[1], ch, n
=AMEMBERS(a1, oObject, 1)
=AMEMBERS(a2, oObject.BaseClass)
DIMENSION aArr(ALEN(a1))
n = 0
FOR i = 1 TO ALEN(a1, 1)
ch = a1[i, 1]
IF a1[i,2]='Property' AND 0=ASCAN(a2, ch)
n = n + 1
aArr[n] = ch
ENDIF
ENDFOR
DIMENSION aArr[n]
ENDPROC
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform