PreviousNextIndex

CONSTRUCTOR statement

Defines a constructor for a class. A constructor is a special type of method that ABL invokes to initialize data for a new object of a class that is instantiated using the NEW function (classes), NEW statement, or DYNAMIC-NEW statement, or to initialize static members of a class.

Note: This statement is applicable only when used in a class definition (.cls) file.
Syntax

CONSTRUCTOR [ PRIVATE | PROTECTED | PUBLIC | STATIC ] class-name  
  ( [ parameter [ , parameter ] ... ] ) : 
  constructor-body 

[ PRIVATE | PROTECTED | PUBLIC | STATIC ]
class-name
( [ parameter [ , parameter ] ... ] )
constructor-body
constructor-logic
END [ CONSTRUCTOR ]
Examples

The following example shows the definition of an instance 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. 

For more examples of constructor definitions, including a static constructor and a constructor for an abstract class, see the descriptions of r-CustObj.cls, r-CustObjStatic.cls, and r-CustObjAbstract.cls in the CLASS statement reference entry.

Notes
See also

Assignment (=) statement, CLASS statement, DESTRUCTOR statement, DYNAMIC-NEW statement, FUNCTION statement, NEW function (classes), NEW statement, Parameter definition syntax, SUPER statement, THIS-OBJECT statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex