Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Copying property values from one object to another
Message
De
14/12/1999 23:37:37
 
 
À
14/12/1999 22:32:39
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00303863
Message ID:
00303893
Vues:
41
>What is the best way of transferring property values from one object to another?
>Let's say I have an object A with properties x, y, and z
>and I have object B with properties q, r, x and y
>I want a method to transfer x and y values from B to A without explicitly "knowing" that the object share those properties in common
>
>I'm currently using AMEMBERS() and vartype() etc , but is there an easier way?

I don't think there's an easy way. FWIW, here;s the code that I use to do the same thing:
FUNCTION CopyProp
LPARA o1, o2

* Copy all property values from one object to another
IF TYPE('o1.Name') <> "C" OR TYPE('o2.Name') <> "C"
	RETURN .F.
ENDIF

lnPropertyCount = AMEMBERS(aProps, o1)

FOR i = 1 TO lnPropertyCount
	IF !ALLTRIM(UPPER(aProps(i)))$"CLASS:PARENTCLASS:BASECLASS:NAME"
		uVal = GETPEM(o1,aProps(i)) && Value of property in source
		IF PEMSTATUS(o2,aProps(i),5) && Does property exist in the second object?
			IF !PEMSTATUS(o2,aProps(i),1) && Is the property readonly?
				IF !PEMSTATUS(o2,aProps(i),2) && Is the property protected?
					o2.WriteExpression(aProps(i), uVal)
				ENDIF
			ENDIF
		ENDIF
	ENDIF
ENDFOR
Erik Moore
Clientelligence
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform