Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copying property values from one object to another
Message
From
15/12/1999 01:44:37
 
 
To
14/12/1999 23:37:37
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00303863
Message ID:
00303914
Views:
25
>>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
>
Thanks for the code sample Eric,
It's always good to see some snippets!
Previous
Reply
Map
View

Click here to load this message in the networking platform