*********************************************************** 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 *** Return: New Object reference *********************************************************** LPARAMETER loInput LOCAL loObject, laFields[1], lnX, lcField, lcType, llClass, ; lnCount, z, lnLength #DEFINE COPYOBJECT_PROPERTYEXCLUSIONLIST ; ",classlibrary,baseclass,comment,controls,objects,"+; "class,name,helpcontextid,whatsthishelpid," +; "tag,picture,onetomany,childalias,childorder,"+; "parent,parentclass,relationalexpr,controlcount," *** 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 = CREATE("Relation") 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 + ",","'" + ; COPYOBJECT_PROPERTYEXCLUSIONLIST) > 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" loObject.ADDPROPERTY(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" loObject.ADDPROPERTY(lcField) ENDIF loObject.&lcField = ; CopyObject(EVAL("loInput."+lcField)) OTHERWISE *** Check if property exists IF TYPE("loObject." + lcField) = "U" loObject.ADDPROPERTY(lcField) ENDIF *** Straight Assignment loObject.&lcField = EVAL("loInput." + lcField) ENDCASE ENDFOR RETURN loObject * EOF CopyObjectRegards,