Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SO what would it take to copy classes?
Message
 
To
12/08/1996 10:46:52
Mark Stanton
The New Software Company Ltd.
Watford, United Kingdom
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00005582
Message ID:
00005588
Views:
28
>Anyone done this?
Yes, I have created a routine (37 lines to be exact) that uses AMEMBERS() and recursively processes sub-objects. It only attempts to pare properties with the same name. It even copies arrays properties. Here is the code. It has a few supporting routines that I will not show here and probably has bugs, because I have not used it to extensively. But it should serve as a start:
FUNCTION CopyObject
PARAMETER oDestObject, oSourceObject
LOCAL x, y, ar2(1,1), ar2s
PRIVATE oDest, oSrc
IF TYPE("m.oSourceObject")=="O"
m.oDest=m.oDestObject
m.ar2s=AMEMBERS(m.ar2, m.oSourceObject, 1)
m.oSrc=m.oSourceObject
ELSE
m.oDest=CREATEOBJECT(m.oDestObject.class)
m.ar2s=AMEMBERS(m.ar2, m.oDestObject, 1)
m.oSrc=m.oDestObject
ENDIF
FOR m.x=1 TO m.ar2s
DO CASE
CASE m.ar2[m.x, 2]=="Property"
* Check to see if the property is available in the dest.
IF PEMSTATUS(m.oDest, m.ar2[m.x,1],5)
IF !PEMSTATUS(m.oDest, m.ar2[m.x,1],1)
IF UPPER(m.ar2[m.x, 1])!="NAME"
m.y=m.ar2[m.x,1]
IF Duke_lib.MacroErrHandler( ;
"=ACOPY(m.oSrc."+y+", m.oDest."+y+")")>0
m.oDest.&y.=m.oSrc.&y.
ENDIF
ENDIF
ENDIF
ENDIF
CASE m.ar2[m.x, 2]=="Object"
* Check to see if the object is available in the dest
IF PEMSTATUS(m.oDest, m.ar2[m.x,1],5)
m.y=m.ar2[m.x, 1]
=CopyObject(m.oDest.&y., m.oSrc.&y.)
ENDIF
ENDCASE
ENDFOR
RETURN m.oDest && CopyObject
Hope this Helps, Peter
Peter Stephens
Visual Records, Inc.

Lead Programmer for the general purpose record keeping system Visual Records. Written primarily in VFP 6.0 with a little C++.
Previous
Reply
Map
View

Click here to load this message in the networking platform