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:
00260416
Views:
17
>>>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

There are a few more things you need to check before doing something like this. Here is a snippet from a routine I ahve that copies properties from one object to another:
FOR i = 1 TO ALEN(aProps)
	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
Previous
Reply
Map
View

Click here to load this message in the networking platform