CONSTRUCTOR [ PRIVATE | PROTECTED | PUBLIC | STATIC ] class-name
( [ parameter [ , parameter ] ... ] ) :
constructor-body
|
[ PRIVATE
| PROTECTED
| PUBLIC
| STATIC
]
STATIC specifies a static constructor that executes exactly once in an ABL session the first time you reference a class type that defines this constructor in its class hierarchy. You cannot invoke a static constructor in any other way or at any other time. You can define only one static constructor for a given class. If you do not define a static constructor, ABL defines a default static constructor to initialize the static members of a class.
( [ parameter [ ,
parameter ] ... ] )
If you are defining an instance constructor, regardless of other statements in the constructor, the first action of the constructor must be a call to another instance constructor in the defining class or in the immediate super class. ABL can call a default super class constructor implicitly, or you can call a super class constructor or another overloaded constructor in the defining class explicitly as the first statement of a constructor. You cannot explicitly call another constructor in any other statement of a constructor, and you cannot call any defined static constructor.
If there is no constructor instance defined in the immediate super class and you do not explicitly invoke a constructor, ABL always implicitly invokes the built-in default super class constructor (without parameters) as the first action. If there is an instance constructor defined in the super class that does not take parameters, you also do not need to explicitly invoke an instance constructor. ABL implicitly invokes this user-defined default super class constructor. You only need to explicitly invoke another instance constructor when the super class has constructors defined for it and all of these constructors take parameters.
If you want to invoke an overloaded instance constructor of the defining class, you must invoke the
THIS-OBJECT statement as the first statement, with parameters that match the parameters of the overloaded constructor with respect to number, data type, and mode. If you invoke an overloaded constructor, and that overloaded constructor does not invoke another overloaded constructor, it must invoke a super class constructor, either implicitly (the default) or explicitly as its first statement. So, in any chain of explicit calls from one overloaded constructor to another, the last overloaded constructor in the chain must invoke a super class constructor.
CONSTRUCTOR PUBLIC CustObj( ):
m_NumCusts = 0.
/* Fill a temp table and get the row count */
FOR EACH Customer NO-LOCK:
CREATE ttCust.
ASSIGN
ttCust.CustNum = Customer.CustNum
ttCust.Name = Customer.Name
m_NumCusts = m_NumCusts + 1.
END.
END CONSTRUCTOR.
|
|
You never explicitly invoke an instance constructor to create a class instance. The constructor is implicitly invoked when you instantiate the defining class using the NEW function (classes), NEW statement, or DYNAMIC-NEW statement, passing any parameters required to identify the instantiating constructor. The instantiating constructor then directly or indirectly calls an instance constructor in its immediate super class, which similarly calls an instance constructor in its immediate super class, and so on for all classes in the class hierarchy, until the default instance constructor of the root ( Progress.Lang.Object class) is called. From this point, the root constructor and all previously called instance constructors complete execution in reverse order of invocation, terminating class instantiation with completion of the initial instantiating constructor.
|
|
You never explicitly invoke a static constructor. All the static constructors of a class hierarchy with static members execute on first reference to a given class within an ABL session. This first reference causes the static constructors of all super classes in the referenced class hierarchy that have static members to execute from top to bottom, terminating with the execution of the static constructor for the most derived class with static members. For any single class with static members, its static constructor runs only once per ABL session or until after the given class is compiled again. If the first reference to a class occurs during class instantiation, this sequence of static constructor execution occurs prior to execution of the instantiating constructor. Thus, all static constructors in a class hierarchy are guaranteed to execute before a class instance is referenced.
|
|
You can handle application errors in an instance constructor as in any ABL block. However, by executing a RETURN ERROR action at the block level or a THROW action at the block level with the presence of a BLOCK-LEVEL ON ERROR UNDO, THROW statement, or a ROUTINE-LEVEL ON ERROR UNDO, THROW statement, the AVM returns the ERROR condition from the constructor block. With this returned ERROR condition, ABL terminates creation of the object. If any part of the class hierarchy has been created (constructors executed), ABL executes the corresponding destructors for those classes automatically and raises ERROR on the statement that instantiated the class. If this constructor is invoked as part of a NEW statement or DYNAMIC-NEW statement, the data element set to receive an object reference to the failed class instantiation remains unchanged. If a RETURN ERROR also includes the option to return a character string value, or you set the ReturnValue property of a Progess.Lang.AppError object that you THROW, you can get this value using the RETURN-VALUE function following the statement that attempted to instantiate the class or in a CATCH block that catches the Progress.Lang.AppError object. For more information, see OpenEdge Development: Object-oriented Programming.
|
|
You can handle application errors in a static constructor similar to an instance constructor. However, an ERROR condition returned from the constructor block is raised on the statement whose class reference caused the static constructor to be invoked (whether or not the statement instantiates the class). With this ERROR condition, ABL fails to loaded the specified class and its entire class hierarchy. In addition, ABL does not load the specified class, or the other classes of its class hierarchy, for the remainder of the ABL session, or until the specified class is recompiled.
|