Creates an instance of a class (object) using the NEW
function and assigns its object reference to an appropriately defined ABL data element. Once
assigned, you can use the object reference to access this class instance and its PUBLIC data
members, properties, and methods. For more information on object references, see the
reference entry for a Class-based object reference:
Syntax
object-reference = new-function [ NO-ERROR ]
|
-
object-reference
- The name of an ABL data element to which you want to assign
the object reference of a new instance of the class specified by new-function.
This data element must be defined as a compatible class or interface
type and can be one of the following:
To be compatible, the object type of object-reference must
be:
- The same class type as the class instantiated by new-function
- A super class of the class instantiated by new-function
- An interface that is implemented by the class instantiated by new-function
-
new-function
- An invocation of the NEW function, which creates an
instance of a specified class and returns an object reference to that instance. This is
the syntax for the NEW function, where object-type-name must specify a class type consistent with the object type
of object-reference: The value of new-function is restricted to alphanumeric characters plus
the symbols #, $, %, and _.
NEW object-type-name ( [ parameter[ , parameter ]...] )
|
The parameter list
specifies the class constructor that is used to instantiate the class. For more
information on the syntax and operation of the NEW function, see the
NEW function (classes)
reference entry.
- NO-ERROR
- The NO-ERROR option is used to prevent the statement from raising ERROR and displaying error messages.
For
the NEW statement with NO-ERROR, if ERROR is raised, then the
object-reference remains unchanged.
Example
The
following code fragment shows the definition of a variable that
is assigned to the object reference for a new class instance:
DEFINE VARIABLE myCustObj AS CLASS acme.myObjs.CustObj NO-UNDO.
myCustObj = NEW acme.myObjs.CustObj ( ).
|
Notes
- After
the assignment, object-reference contains a copy
of the object reference value returned by new-function,
which points to the same object instance, not a copy of the object
created by new-function.
- Although you can assign an object reference to a temp-table
field defined as a Progress.Lang.Object class type, you cannot assign an object reference to
a field in a database table. For more information, see OpenEdge
Development: Object-oriented Programming.
- This statement can raise errors during the execution of constructors for
the class being instantiated by new-function,
or for any class in its inherited class hierarchy. For example:
- A constructor in the class hierarchy executes the RETURN statement with the
ERROR option or the UNDO statement with the THROW or
RETURN ERROR options.
- The class definition file for the class, a super class, or an
interface could not be found.
- The run-time parameters of the constructor for the class, or
a constructor for a class in the inherited class hierarchy, are
not compatible.
When the AVM encounters one of these
errors, and the constructor cannot create the class instance or
its inherited class hierarchy, the AVM automatically invokes the
destructor for any class that has already been constructed while
building the class hierarchy for the object.
For more information
on errors raised by instantiating classes, see OpenEdge Development:
Object-oriented Programming.
- The ABL Virtual Machine (AVM) automatically deletes (garbage collects)
any class instance that you create with the NEW statement some time after
no reference to that object exists in the ABL session. However, you can force any class
instance to be deleted immediately by using the DELETE OBJECT statement.
For more information on garbage collection for class instances, see the DELETE OBJECT statement reference
entry.