Create - cObject

Creates an object based on the passed Class Id

Type: Function

Return Data Type: Handle

Parameters: integer iClassId

iClassIdThe Class Id of the object to be created.

Return Value

The object handle of the newly created object.

Function Create integer iClassId Returns Handle

Call: Get Create iClassId to HandleVariable


The Create function is used to dynamically create objects. It creates an object based on the passed iClassId. The object that receives the message becomes the parent object.

For example, an array object could be created as follows:

Handle hoObject
Get Create (RefClass(cObject)) to hoObject

An object created using the Create message does not have a meaningful name, and it should be accessed using its object handle. For example:

Procedure ProcessList
    Handle hoArray
    Integer i

    Get Create (RefClass(Array)) to hoArray
    For i from 0 to 100
        Set Value of hoArray i to "Test Data"

    Send PrintData hoArray
    Send Destroy of hoArray

You can use CreateNamed to create named objects dynamically.

When dynamically creating an object with a visual interface, such as a Form or TextBox, the Add_Focus message needs to be sent to add the object to the focus tree and page it.


This sample shows how to dynamically create a LineControl object using Create and add it to the focus tree and page it using Add_Focus. oViewName is the name of the view object to which the LineControl is beign added.

Function CreateLineControl Integer iX Integer iY Handle hoParentId Returns Handle
    Handle hoObject
    Integer iRetVal

    Get Create (RefClass(LineControl)) to hoObject
    Get msg_Add_Focus of hoObject hoParentId to iRetVal

    Set Location of hoObject to iX iY
    Set Size of hoObject to 2 100

    Function_Return hoObject
Handle hoObject
Get CreateLineControl 12 12 oViewName to hoObject

Objects created using the Create function are typically destroyed using the Destroy message.

In legacy code, the class id was typically passed as a constant consisting of the symbol "U_" followed by the class name.

See Also

Destroy | Dynamic Objects | RefClass function