Skip to content

Class: cObject

Include: Built in; no package required.

Root DataFlex object class for object handles, hierarchy, lifecycle hooks, child objects, and delegation.

Hierarchy

  • cObject

Package: Built in; no package required.

Description

cObject is the root DataFlex object class. It provides object identity, naming, parent/child hierarchy, construction and destruction hooks, dynamic child creation, delegation, neighborhood lookup, and class inspection.

Object lifecycle

  • Construct_Object runs during object construction.
  • End_Construct_Object runs after object construction has finished.
  • Destroy destroys dynamically created objects.
  • After Destroy, do not reuse the old handle.
  • The null object and desktop object cannot be destroyed and raise a DataFlex error.

Dynamic objects

Create and CreateNamed create child objects at runtime and return a Handle. CreateNamed requires a non-empty local name; empty names raise a DataFlex error.

Object identity and hierarchy

Object_Id returns the current object handle. Name returns the qualified object name, such as oMain.oChild; setting it changes the object's local name. Object_Label returns the local label, such as oChild. Parent identifies the parent object, Child_Count returns the number of direct children, and ChildByIndex returns a child by position.

ChildByIndex uses zero-based indexes and raises a DataFlex error when the index is below zero or greater than or equal to Child_Count.

Delegation and neighborhood

Delegation_Mode controls unknown-message delegation:

  • DELEGATE_TO_PARENT delegates to the parent.
  • NO_DELEGATE_OR_ERROR stops without raising an error.
  • NO_DELEGATION raises a DataFlex error.
  • RETURN_INVALID_MESSAGE returns the invalid message value.
  • DELEGATE_PRIOR_LEVEL delegates to the prior object in the call stack.

peNeighborhood controls object-name visibility:

  • nhNo does not participate in a neighborhood.
  • nhPublic allows descendant objects to address each other.
  • nhPrivate creates a private neighborhood where descendants cannot address each other.

Class inspection

Class returns the class id for this object. Base_Class returns the parent class id for this object's class. ObjectClass returns this object's class id, resolving cloned class information to the original class where applicable. ClassSuperClass returns the parent class id for a class reference. IsClassOfClass returns a Boolean indicating whether one class is the same as, or derives from, another class. IsObjectOfClass returns a Boolean indicating whether this object is an instance of the requested class.

Examples

Static object tree

Object oMain is a cObject
    Object oChild is a cObject
    End_Object
End_Object

Dynamic object

Procedure CreateDynamicObject
    Handle hoObj

    Get CreateNamed (RefClass(cObject)) "oDynamic" to hoObj
    Send Destroy of hoObj
End_Procedure