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 defines the default initialization function to be called each time a COMBOBOX form field is created when loading forms.

Use this method 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 when the function is invoked. 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.

Note: The error -1338 is raised when the function name mismatches, or when the module implementing the function is not yet loaded.

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