Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Copy a Object ??
Message
From
01/09/1999 15:46:51
Charlie Schreiner
Myers and Stauffer Consulting
Topeka, Kansas, United States
 
 
To
01/09/1999 10:26:34
Vinod Parwani
United Creations L.L.C.
Ad-Dulayl, Jordan
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00258802
Message ID:
00260313
Views:
22
Here's what I use to synchronized two objects. Use it if it helps.
* Author: Charlie Schreiner 05/05/1998
* 
* Put two objects into sync where object 1 is given object 2's values
* Third parameter is optional to determine which properties we don't care about
* or which properties we DO care about.
* Forth parmeter is optional to determine whether the 3rd parmeter 
* excludes or includes properties.
* Return .t. if objects were already in perfect harmony.
*
* Example: ObjSync(ObjectGettingSet, ;
* 					ObjectWithValues, ;
*					["HelpContextID","Top"], .F.
* Notice the brackets to contain the exclude/include strings.

LPARAMETERS Obj1, Obj2, String, Include
LOCAL PropertyNumber
IF NOT TYPE("m.Include") = "L"
	Include = .F.
ENDIF

IF TYPE("m.String") = "C"
	String = UPPER(m.String)
ELSE
	IF NOT m.Include
		String = ["HELPCONTEXTID"]
	ENDIF
ENDIF

LOCAL ARRAY aObj1[1]
LOCAL ARRAY aObj2[1]
LOCAL RetVal, CheckIt
RetVal = .T.
AMEMBERS(aObj1, m.Obj1)		&& Put the properties of object 1 into an array.

AMEMBERS(aObj2, m.Obj2)		&& Put the properties of object 2 into an array.

SET EXACT ON
FOR PropertyNumber = 1 TO ALEN(aObj2,1)
	PropertyName = aObj2[m.PropertyNumber]
	* First try to find Object2's property in Object1.
	IF ASCAN(aObj1,m.PropertyName) > 0 ;
	  AND NOT PEMSTATUS(m.Obj1,m.PropertyName,1)
		* Found it and not readonly
		CheckIt = .F.
		IF m.Include 
			IF NOT EMPTY(m.String) 
				CheckIt = INLIST(UPPER(m.PropertyName), &String.) 
			ENDIF
		ELSE
			CheckIt = NOT INLIST(UPPER(m.PropertyName),&String.) 
		ENDIF			
		IF m.CheckIt
			** If it's defined, see if they are equal.
			IF NOT EVAL("m.Obj2." + m.PropertyName) = EVAL("m.Obj1." + m.PropertyName) ;
					AND NOT ISNULL(EVAL("Obj2." + m.PropertyName))
					* Added the ISNULL check 7/26/1999 CLS.
				STORE EVAL("Obj2." + m.PropertyName) TO ("m.Obj1." + m.PropertyName)
				RetVal = .F.		&& Mismatch was found.
			ENDIF
		ENDIF
	ENDIF
ENDFOR
SET EXACT OFF		

RETURN m.RetVal
Charlie
Previous
Reply
Map
View

Click here to load this message in the networking platform