Private Objects

DataFlex classes can be defined to contain nested objects of any other class. Each time an instance of the new class is created the nested objects are also created. Nested objects are useful tools for defining classes that have sophisticated behavior and data storage requirements.

Nested objects that are part of a class's definition become private attributes of the class. That is, they are part of the class's internal design. Whenever an object is destroyed any nested objects it defines are also automatically destroyed.

Nested objects are declared in the class's constructor method (Construct_Object). Below is an example class definition that contains a nested object:

Class cStorageForm is a Form

    Procedure Construct_Object

        Forward Send Construct_Object


        Object oStorageArray is an Array




    Procedure DoAppendValue

        Integer iItemCount

        String  sFormValue

        Get Value       of Self 0        To sFormValue

        Get Item_Count  of oStorageArray To iItemCount

        Set Array_Value of oStorageArray iItemCount  To sFormValue



    Procedure DoClearStorage

        Send Delete_Data  To oStorageArray



    Function StorageValue Integer iItem Returns String

        String sReturnValue

        Get String_Value of oStorageArray iItem To sReturnValue

        Function_Return sReturnValue



The above example defines a new Form class cStorageForm that contains a nested array object. Three methods are defined as an interface to the nested array. DoAppendValue retrieves the Form object's value and appends it to the nested array; DoClearStorage clears the data in the nested array and StorageValue returns an indexed value from the array.

The methods defined in this example call methods from the current object and from the nested array object. For the purpose of clarity the Self keyword has been used when calling a method of the current object. However, this is redundant since the current object is the default recipient of any message.