Functions and Directives

Function ClassObject() Foundation

Retrieves the class object of any class.

ClassObject( <cClassName> ) --> oClassObject | NIL
The character expression <cClassName> indicates the name of the class whose class object should be returned.

The function returns the class object of the class with the name <cClassName>. The return value is NIL when the class does not exist.


The class object of any class can be retrieved with the ClassObject() function. This includes both static and dynamic classes. Static classes are known at compile time and have a class function. They already exist in Xbase++ or are declared within CLASS...ENDCLASS. In contrast, a dynamic class is created at runtime by the ClassCreate() function. Dynamic classes have no class function but are represented only by their class object.

The function ClassObject() is especially useful for detecting whether or not a dynamic class already exists in a program, whereas the existence of static classes can be checked with the Type() function.

Check if a class exists

// The example demonstrates how to test for the existence of 
// static and dynamic classes. The function Type() can only 
// detect static classes which have a class function. 

#include "" 

   LOCAL oClass, oObject 

   * Static class (with class function) 
   ? Type( "XbpDialog()" )             // Result: O 

   * Dynamic class (without class function) 
   ? Type( "MyClass()" )               // Result: U 

   * Create class without referencing the class object 
   IF ClassObject( "MyClass" ) == NIL 
      ClassCreate( "MyClass",, {{"IVar",CLASS_EXPORTED}} ) 

   * Retrieve class object of dynamic class 
   oClass := ClassObject( "MyClass" ) 
   ? oClass:className()                // Result: MYCLASS 

   * Instantiate dynamic class 
   oObject      := oClass:new() 
   oObject:IVar := "Hello World" 

   ? oObject:IVar                      // Result: Hello World 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.