OBJECT()

OBJECT()

Top  Previous  Next

 

The OBJECT() function instantiates an object for object oriented programming.

 

 

Format

 

OBJECT(cat.name, {args...})

OBJECT(obj.var)

 

where

 

cat.nameis the name of the catalogued CLASS module defining the object.

 

argsare optional arguments that will be passed into the CREATE.OBJECT subroutine.

 

obj.varis a reference to an instantiated object.

 

 

The first form of the OBJECT() function loads the catalogued class module defined by cat.name and creates an object that references it. The function returns an object reference that should be stored in a program variable.

 

OBJ = OBJECT("MYOBJECT")

 

If the class module includes a public subroutine named CREATE.OBJECT this is executed as part of object instantiation.

 

Copying an object reference variable creates a second reference to the same object, not a new instantiation of the same object. The second form of the OBJECT() function creates a new object as a clone of an existing object. The CREATE.OBJECT subroutine is not executed.

 

NEWOBJ = OBJECT(OBJ)

 

 

An object remains in existence until the last variable referencing it is overwritten or discarded. At this point, if the class module includes a public subroutine named DESTROY.OBJECT, it will be executed.

 

Attempting to instantiate an object that does not exist will result in an abort. Alternatively, the error can be trapped by use of an exception handler:

TRY

  OBJ = OBJECT("MYOBJECT")

CATCH SYS$ANY

  DISPLAY "Cannot load object"

END

 

 

See also:

Object oriented programming, CLASS, DISINHERIT, INHERIT, OBJINFO(), PRIVATE, PUBLIC.