Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Copying property values from one object to another
Message
De
15/12/1999 20:59:39
 
 
À
14/12/1999 23:37:37
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00303863
Message ID:
00304476
Vues:
24
Just for interest, I've been playing with the classes created by..
SCATTER NAME
The object so created doesn't have a baseclass, class etc. Just the user defined properties. NICE.
However the only way I can figure to create one of these beasties is via the SCATTER NAME approach. Is there any other way? Anyone?
So I pass this classless class as a parameter to my "observer" class in the init event. The "observer" updates it's properties *quickly* and easily then from the class that it's observing (usually a form).


>>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
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform