Array Properties

Special consideration needs to be given for accessing data that is stored in array properties. The Get and Set commands that are used for accessing a property's data can only be used to get and set the entire array. This works just like an array variable assignment.

To read or write individual array property elements, it is necessary to get the property to a local array variable of the same type. You would then manipulate the data of this local array and write back the changes by setting the array property once again.

Example…

Class cMyButton is a Button

 

    Procedure Construct_Object

        Forward Send Construct_Object

        // Declare an array property

        Property String[] psNames

    End_Procedure

 

    Procedure StoreName String sNewName

        String[] sNames     // create a local array variable

        Integer  iElementCount

 

        // get the array property to the variable.

        Get psNames to sNames

        

        // Add the new name.

        Move (SizeOfArray(sNames)) to iElementCount

        Move sNewName to sNames[iElementCount]

 

        // Save the change back to the array property.

        Set psNames to sNames

    End_Procedure

 

End_Class

Accessing array properties utilizes the copy-on-write concept, which means that getting/setting array properties do not impose a full copy operation itself. If you are only reading the array elements in a procedure, then the copy to a local array variable is very fast. DataFlex will only copy a reference to the array until the first time that you perform a write to this copy. At the time of the first write a full copy will be made. Thus if your process never writes to the copy, it will be very efficient.

For more information refer to Setting Property Values and Reading Property Values.