ui.ComboBox.setDefaultInitializer

Define the default initializer for combobox form items.

Syntax

ui.ComboBox.setDefaultInitializer(
   initializer STRING )
  1. initializer is the name of the initialization function.

Usage

The ui.ComboBox.setDefaultInitializer() class method specifies a default initialization function to be called each time a COMBOBOX form field is created when loading forms.

Use this method if you want to define a global/default initialization function for all comboboxes of the program. For individual comboboxes, consider using the INITIALIZER form field attribute instead.

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.

The function is called with the ui.ComboBox object as the parameter.

The combobox initialization functions are typically used to fill the drop down list with items.

Example

The form file form1.per:
LAYOUT 
GRID
{   
[cb1             ]
}   
END 
END 
ATTRIBUTES
COMBOBOX cb1 = FORMONLY.city;
END

The main module:

IMPORT FGL setup
MAIN
    DEFINE city STRING
    CALL setup.init_combo_setup(TRUE)
    CALL ui.ComboBox.setDefaultInitializer("cb_init")
    OPEN FORM f1 FROM "form1"
    DISPLAY FORM f1 -- initialization function is called
    INPUT BY NAME city
END MAIN
The imported module setup.4gl:
PRIVATE DEFINE with_undef BOOLEAN

PUBLIC FUNCTION init_combo_setup(wu)
    DEFINE wu BOOLEAN
    LET with_undef = wu
END FUNCTION

PUBLIC FUNCTION cb_init(cb)
  DEFINE cb ui.ComboBox
  CALL cb.clear()
  IF with_undef THEN
     CALL cb.addItem(0,"Undefined")
  END IF
  CALL cb.addItem(0,"Paris")
  CALL cb.addItem(0,"London")
  CALL cb.addItem(0,"Rome")
  ...
END FUNCTION