Specifying a Function to Initialize all Forms

To assist in standardizing forms, you can create an initializer function in your program that will be called automatically whenever any form is opened. A reference to the form object is passed by the runtime system to the function.

Example initializer function:

01 FUNCTION myforminit(f1)
02  DEFINE f1 ui.Form 
03
04  CALL f1.loadTopMenu("mytopmenu")
05   ...
06
07 END FUNCTION

The setDefaultInitializer() method applies to all forms, rather than to a specific form object. It is a class method, and you call it using the class name as a prefix. Specify the name of the initializer function in lowercase letters:

CALL ui.Form.setDefaultInitializer("myforminit")  

You can call the myforminit function in your program as part of a setup routine. The myforminit function can be in any module in the program.

Example 5

01 MAIN
02  CALL ui.Form.setDefaultInitializer("myforminit")
03  OPEN WINDOW w1 WITH FORM "testform"
04  MENU
05   ON ACTION quit 
06    EXIT MENU
07  END MENU
08  OPEN WINDOW w2 WITH FORM "testform2"
09  MENU
10   ON ACTION quit 
11    EXIT MENU
12  END MENU
13 END MAIN
This figure is a screenshot of form testform initialized with the myforminit initializer function.

Figure 1. Form testform with initializer function

This figure is a screenshot of form testform2 using the same initializer function as form testform.

Figure 2. Form testform2 using the same initializer function.