Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based Objects : Instantiating and managing class-based objects : Creating a class instance
 

Creating a class instance

You can use any one of the following four ABL elements to create an instance of a class:
*NEW function
*NEW statement
*DYNAMIC-NEW statement
*New( ) method of the Progress.Lang.Class class
At run time, the given function, statement, or method locates the specified class type on the PROPATH using the package information in the class type name (or as specified in an appropriate USING statement at compile time) and invokes the specified constructor to create a new instance of the class. The NEW function returns an object reference to the class instance (class-based object) it creates, which you can use directly in an expression to access a member of the class without assigning the object reference to a variable. The NEW statement and the DYNAMIC-NEW statement each instantiate the class and assign its object reference to a variable in a single operation. The New( ) method of the Progress.Lang.Class class returns an object reference to the instantiated class as a Progress.Lang.Object.
The basic difference between them is that the DYNAMIC-NEW statement and the New( ) method allow you to instantiate the class from information evaluated at run time, while both the NEW statement and NEW function require that you specify the class type using a type name that is resolved at compile time. The New( ) method also provides the flexibility of using run-time information obtained through reflection to specify the class and constructor parameters (if any) that it uses to instantiate the class.
* NEW and DYNAMIC-NEW statements
* New( ) method