ui.Form.setDefaultInitializer

Define the default initializer for all forms.

Syntax

ui.Form.setDefaultInitializer(
   initializer STRING )
  1. initializer is the name of a function in the program.

Usage

Specify a default initialization function with the ui.Form.setDefaultInitializer() method, to implement global processing when a form is opened.

The method takes the name of the initialization function as a parameter.

Important:
  • The initialization function name is case insensitive.
  • The module defining the initialization function must have been loaded before the function is invoked. The error -1338 is raised if the module is not yet loaded, or when the function name mismatches. To make sure that the module is loaded, define other functions in the module, that are invoked with a regular CALL instruction.

When a form is loaded with OPEN FORM / DISPLAY FORM or with OPEN WINDOW ... WITH FORM, the initialization function is called with a ui.Form object as a parameter.

Example

The form file form1.per:
LAYOUT 
GRID
{   
[f1             ]
}   
END 
END 
ATTRIBUTES
EDIT f1 = FORMONLY.cust_name;
END

The main module:

IMPORT FGL setup

MAIN
    DEFINE cust_name STRING
    CALL setup.init_form_setup(FALSE)
    CALL ui.Form.setDefaultInitializer("form_init")
    OPEN FORM f1 FROM "form1"
    DISPLAY FORM f1 -- initialization function is called
    INPUT BY NAME cust_name
END MAIN
The imported module setup.4gl:
PRIVATE DEFINE with_toolbar BOOLEAN

PUBLIC FUNCTION init_form_setup(tb)
    DEFINE tb BOOLEAN
    LET with_toolbar = tb
END FUNCTION

PUBLIC FUNCTION form_init(f)
    DEFINE f ui.Form
    IF with_toolbar THEN
       CALL f.loadToolBar("common_toolbar")
    END IF
END FUNCTION