Construct_Object - cObject
Object constructor. Initializes the object during object creation in class definitions
Type: Event
Syntax
Procedure Construct_Object
Description
This is the object constructor method. In a sub-class, Construct_Object is used to:
- Create New Properties
- Assign Property values
- Create child-objects
Construct_Object is called at the start of object construction. End_Construct_Object is called at the end of class construction.
If you create a Construct_Object method in a sub-class, you must forward send the message in the top of that method.
You may not define Construct_Object inside of an object. It can only be defined within classes.
A new class declaration should follows this general form:
Class NewClassName is a SuperClassName
// Construct_Object: Object constructor
Procedure Construct_Object
// you MUST always forward send this message
Forward Send Construct_Object
// Define new properties: Property {Type} {pxName} {initial_value}
:
// Create child objects
Object oSampleObject is a cObject
End_Object
:
// Set property values:
Set pSampleProperty to Value
:
End_Procedure // Construct_Object
// Create and augment procedure and functions
:
Procedure End_Construct_Object
// change any properties or call methods before finalizing the object
:
// you MUST always forward send this message
Forward Send End _Construct_Object
End_Procedure
End_Class // NewClassName
Object instantiation should follow this general form:
Object oObjectName is a cNewClassName
End_Object // oObjectName
or
Get Create U_cNewClassName to hoNewObjectID
Here is an example of a new class called cRedForm, which is a standard Form with red text.
Class cRedForm is a Form
Procedure Construct_Object
Forward Send Construct_Object
Set TextColor to clRed
End_Procedure // Construct_Object
End_Class // cRedForm
Here is an example of an object instantiated from the cRedForm class.
Object oMyRedForm is a cRedForm
End_Object // oMyRedForm
You should never send the messages Construct_Object or Destroy_Object. These are event methods that are automatically executed whenever an object is being created or destroyed. Objects are constructed when an object declaration statement is executed. If you wish to manually destroy an object you should execute the Destroy message.
For more information refer to: the Destroy method and Dynamic Objects.
| Col 1 | Col 2 |
|---|---|
| Note: | Although Construct_Object and End_Construct_Object are not documented in subclasses of cObject, these two constructor methods are always part of the expected interface. They are an essential part of creating any subclass. Technically, these methods are constructors and not events - but they are documented here as events |
See Also
Constructors and Destructors | Classes | Objects | End_Construct_Object