User Class Constructors
User class constructors (initializers) extend the capabilities of OpenROAD user classes by enabling developers to specify how the user classes are initialized (what 4GL code is to be run) when they are instantiated. The capabilities of user class constructors parallel the capabilities of the initialize statement for a frame or field script.
You may specify the initialize block, the same block of code available for 4GL frames and procedures, to serve as user class constructors. The primary purpose of constructors is to execute the 4GL code needed to initialize data within the user class instance when the user class is created.
In the initialize section for a user class, you may declare variables that are local to the user class instance being created. These variables are available to all the methods defined for the user class, but hidden from the 4GL that creates the user class instance or calls the user class’s methods.
When a user class instance containing a constructor is created at runtime (when a field or declared variable whose data type in that user class is instantiated, or when the 4GL code executes a create method call), the constructor code block runs to completion before the next 4GL statement is run. This means that while using the debugger:
• You could step over one statement to the next and perhaps be unaware that one or more user class constructor code blocks were run.
• You could step from one statement into the next, into a constructor block that needs to execute before the next logical statement is run in the application.
Global variables that create instances of user classes containing an initialize execute the constructors independently of the other frames, procedures, and so on, that represent an application.
Example of a user class constructor:
initialize =
declare
timetwo = procedure returning integer;
value = integer not null;
enddeclare
begin
Curobject.uc1_min = 1;
curobject.uc1_max = 100;
curobject.uc1_value = ifnull(timetwo(num = 5), 0);
value = 50;
end
method GetInstValue() =
{
return value;
}
procedure timetwo(num = integer not null) =
{
return num*2;
}