wwUtils::CopyObjectProperties

This function copies properties between two objects in a flat manner. Child objects or arrays are not taken into account - this is a single level function.

If you have multiple level objects you can explicitly copy each of the child objects.

The function also provides a parameter to determine which object is used as the source object that is used for parsing the properties to update. This is especially useful if one of the objects in question is a COM object which cannot return property values from AMEMBERS().

CopyObjectProperties(loSource,loTarget,
                     lnObjectStructureObject, 
                     llDontParseObjects,
                     lcPropertyExclusionList)

Return Value

nothing

Parameters

loSource
The Source object to copy properties from.

loTarget
The target object to copy properties to.

lnObjectStructureObject
optional - a value of 1 or 2 which indicates which of the two objects is used as an object map for the property parsing. If not specified 1 is used.

llDontParseObjects
If true won't try to parse child objects. If false child objects are attempted to be parsed. Note: parsing child objects can cause problems if you have nested object references (ie. child referencing parent objects) which may cause a stack overflow error.

lcPropertyExclusionList
optional - A comma delimited list of properties that are not copied.

Remarks

The method handles assignment errors and missing fields with internal exception blocks. No errors are returned and if an assignment error occurs the original property value is simply left as is.

Example

The following is a simple example of copying a single level object into another object of same structure.

loSrc = CREATEOBJECT("Empty")

ADDPROPERTY(loSrc,"Name","Rick")
ADDPROPERTY(loSrc,"Company","West Wind")
ADDPROPERTY(loSrc,"Entered",DATETIME() - 100)

loTrg = CREATEOBJECT("Empty")

ADDPROPERTY(loTrg,"Name","")
ADDPROPERTY(loTrg,"Company","")
ADDPROPERTY(loTrg,"Entered",DATE()-1000)


*** Copy the object with stucture based on second and no property exclusions
CopyObjectProperties(loSrc,loTrg,2,.f.,"")

THIS.AssertTrue(loSrc.Name = loTrg.Name)
THIS.AssertTrue(loSrc.Entered = loTrg.Entered)

The following demonstrates a complex hierarchical object copy:

loSrc = CREATEOBJECT("Empty")

ADDPROPERTY(loSrc,"Name","Rick")
ADDPROPERTY(loSrc,"Company","West Wind")
ADDPROPERTY(loSrc,"Entered",DATETIME() - 100)

loSrc2 = CREATEOBJECT("EMPTY")
ADDPROPERTY(loSrc2,"Street","32 Kaiea Place")
ADDPROPERTY(loSrc2,"Number",10)
ADDPROPERTY(loSrc2,"Zip","97031")
ADDPROPERTY(loSrc2,"Entered",DATE())

ADDPROPERTY(loSrc,"Address",loSrc2)

laItems = ADDPROPERTY(loSrc,"Items[3]",.F.)
loSrc.Items[1] = "Rick"
loSrc.Items[2] = "Strahl"
loSrc.Items[3] = "West Wind"

ADDPROPERTY(loSrc,"Addresses",CREATEOBJECT("Collection"))
loSrc.Addresses.Add(loSrc.Address)
loSrc.Addresses.Add("32 Kaiea Place")


loTrg = CREATEOBJECT("Empty")

ADDPROPERTY(loTrg,"Name","")
ADDPROPERTY(loTrg,"Company","")
ADDPROPERTY(loTrg,"Entered",DATE()-1000)


loTrg2 = CREATEOBJECT("EMPTY")
ADDPROPERTY(loTrg2,"Street","")
ADDPROPERTY(loTrg2,"Number",0)
ADDPROPERTY(loTrg2,"Zip","")
ADDPROPERTY(loTrg2,"Entered",DATE()-1000)

ADDPROPERTY(loTrg,"Address",loTrg2)
ADDPROPERTY(loTrg,"Addresses",NULL)

ADDPROPERTY(loTrg,"Items[1]",.F.)

*** Copy object with structure of second object and no propert exclusions
CopyObjectProperties(loSrc,loTrg,2,.f.,"")

THIS.AssertTrue(loSrc.Name = loTrg.Name)
THIS.AssertTrue(loSrc.Entered = loTrg.Entered)

THIS.AssertTrue(loSrc.Address.Street = loTrg.Address.Street)
THIS.AssertTrue(loSrc.Address.Entered = loTrg.Address.Entered)
THIS.AssertTrue(loSrc.Address.Number = loTrg.Address.Number)

this.AssertTrue(loSrc.Items[2] = loTrg.Items[2])

this.AssertTrue(loSrc.Addresses[1].Street == loTrg.Addresses[1].Street)
this.AssertTrue(loSrc.Addresses[2] == loTrg.Addresses[2])

See also:

Library wwUtils | wwUtils::CopyObject

© West Wind Technologies, 1996-2019 • Updated: 08/13/16
Comment or report problem with topic