In wwUtils the function CopyObjectProperties() initializes lcPropertyExclusionList to equal a defined variable as follows:
#DEFINE STOCK_PROPERTY_EXCLUSION_LIST ",activecontrol,classlibrary,baseclass,comment,controls,objects,controlcount,parentalias,parentclass,helpcontextid,whatsthishelpid,tag,onetomany,childalias,childorder,relationalexpr,timestamp_column,class,name,parent,width,height,top,left,picture,"
Before I call CopyObjectProperties, how can I get a copy of the default exclusion list shown above? Starting from the default, I would like to alter the list to allow one or more properties in the list to be copied. The following code generates a "Program Error, variable not found!"
myDefaultList = STRTRAN(STOCK_PROPERTY_EXCLUSION_LIST,",name","")
thanks
One solution is to use Amembers(laDummy,yourObject) which creates an array of all the object's PEMs. Scan through the array and create a comma separated string which you can edit manually.
thank you for the suggestion.
What I'm wondering and hoping Rick might have a suggestion to is a way to read his default value from within my application.
What I'm wondering and hoping Rick might have a suggestion to is a way to read his default value from within my application.
Hi Harvey,
To do what you want, Rick would need to move the #define statement into a separate .h file that you can #include.
I think all you can do right now it duplicate the string in your own code (with your desired changes) and pass it as a parameter.
Carl
Not really sure why I decided to inline the list of property exclusions like that. The better approach is to parameterize that list so you can pass in your own list.
Changing CopyObject()
to this:
*** ALWAYS IGNORE LIST - FoxPro control properties
#DEFINE STOCK_PROPERTY_EXCLUSION_LIST ",activecontrol,classlibrary,baseclass,comment,controls,objects,controlcount,"+;
"parentalias,parentclass,helpcontextid,whatsthishelpid," +;
"tag,onetomany,childalias,childorder,relationalexpr,timestamp_column," +;
"class,name,parent,width,height,top,left,picture,"
***********************************************************
FUNCTION CopyObject
*******************
*** Author: Rick Strahl, West Wind Technologies
*** http://www.west-wind.com/
*** Function: Function that copies an object and all of
*** it child object into a totally new object
*** reference that is not based on a previous
*** reference
*** Assume: Support for 1 dimensional arrays only
*** Pass: loObject - Existing object reference to copy
*** lcPropertyExclusionList - list of properties to not copy
*** Return: New Object reference
***********************************************************
LPARAMETER loInput, lcPropertyExclusionList
LOCAL loObject, laFields[1], lnX, lcField, lcType, llClass, ;
lnCount, z, lnLength
IF EMPTY(lcPropertyExclusionList)
lcPropertyExclusionList = STOCK_PROPERTY_EXCLUSION_LIST
ENDIF
*** Check if we can instantiate input object class
IF TYPE("loInput.Class") = "C"
*** If we have a class create it
loObject = CREATEOBJECT(loInput.CLASS)
ELSE
*** SCATTER NAME Objects don't have a class
loObject = CREATEOBJECT("EMPTY")
ENDIF
*** Grab member properties and loop through 'em
lnCount = AMEMBERS(laFields, loInput)
FOR lnX=1 TO lnCount
lcField = LOWER(laFields[lnX])
*** Ignore stock properties
IF AT("," + lcField + ",","'" + ;
lcPropertyExclusionList) > 0
LOOP
ENDIF
*** Grab the type
lcType = TYPE("loInput."+lcField)
DO CASE
*** Must check for array properties first
CASE TYPE([ALEN(loInput.] + lcField + [)]) = "N"
*** Add property if it doesn't exist
IF TYPE("loObject." + lcField) = "U"
ADDPROPERTY(loObject,lcField + "[1]")
ENDIF
*** Create the array then run through
*** NOTE: only 1d supported
lnLength = ALEN(loInput.&lcField)
DIMENSION loObject.&lcField[lnLength]
FOR z=1 TO lnLength
IF TYPE("loInput." +lcField + "[z]")="O"
loObject.&lcField[z] = ;
CopyObject(EVAL( "loInput." + ;
lcField + "[z]"))
ELSE
loObject.&lcField[z] = EVAL("loInput." + ;
lcField)
ENDIF
ENDFOR
*** Recursive calls for objects
CASE lcType = "O"
IF TYPE("loObject." + lcField) = "U"
ADDPROPERTY(loObject,lcField)
ENDIF
loObject.&lcField = ;
CopyObject(EVAL("loInput."+lcField))
OTHERWISE
*** Check if property exists
IF TYPE("loObject." + lcField) = "U"
ADDPROPERTY(loObject,lcField)
ENDIF
*** Straight Assignment
loObject.&lcField = EVAL("loInput." + lcField)
ENDCASE
ENDFOR
RETURN loObject
* EOF CopyObject