Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Copy a Object ??
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00258802
Message ID:
00260408
Vues:
20
>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform