Chapter 3 The Application Description Language

3.22 Metaclass Operations

The future development of editors in the ADL requires the capability to create ADL subclasses dynamically. Such an editor may need to access the class (metaclass object) of a wrapped or ADL class. The classOf operator, when applied to an object identifier or an object handle, returns a handle to the corresponding metaclass object. It may also be necessary to send a message to the metaclass object of a named class. The operator theClass, when prefixed to a class identifier, likewise returns a handle to the specified class.
Run-time Type Checking Using isKindOf()
class MyClass : MyBase { ... } myObject;

class YourClass { ... };

on Foo

{

if ( isKindOf( &myObject, theClass MyBase ))

{ /* Do This */ }

if ( isKindOf( &myObject, theClass YourClass ))

{ /* Don't do this */ }

}

The isKindOf(hObject,hClass) built-in function provides run-time type checking of ADL handles. You can call it with two arguments: the first is a handle to an object, the second is a handle to the metaclass object for a class. The second argument is usually derived from one of the expressions shown in Figure 3.42.

The isKindOf() function returns TRUE if and only if the class pointed to by the second argument is the class or a base of the class of the object pointed to by the first argument. You can create an instance of a class from a handle to the metaclass object using the new operator by enclosing the handle in parentheses, as shown in Figure 3.43.
Creating a Class Instance from the Handle to a Metaclass Object
handle hButton = new ( theClass XFbutton );

handle hButton = new {'Create, self} => ( theClass XFbutton );


AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker