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 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 initialization function is called with the ui.ComboBox object as the parameter.

The combobox initialization functions typically fill the drop down list of COMBOBOX fields with items.

For more details about combobox initializer programming, see Filling a COMBOBOX item list.

Example

The form file form1.per:
LAYOUT 
GRID
{
[cb1             ]
[cb2             ]
[cb3             ]
}   
END
END
ATTRIBUTES
COMBOBOX cb1 = FORMONLY.city1, NOT NULL; -- Gets default initializer
COMBOBOX cb2 = FORMONLY.city2, NOT NULL; -- Gets default initializer
COMBOBOX cb3 = FORMONLY.city3, NOT NULL, INITIALIZER=cb_init_2;
END

The main module:

IMPORT FGL setup
MAIN
    DEFINE rec RECORD city1, city2, city3 STRING END RECORD
    CALL setup.init_combo_setup(TRUE)
    CALL ui.ComboBox.setDefaultInitializer("cb_init_1")
    OPEN FORM f1 FROM "form1"
    DISPLAY FORM f1 -- initialization function is called
    INPUT BY NAME rec.*
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_1(cb)
  DEFINE cb ui.ComboBox
  CALL cb.clear()
  IF with_undef THEN
     CALL cb.addItem(0,"<undef>")
  END IF
  CALL cb.addItem(0,"London")
  CALL cb.addItem(0,"Paris")
  CALL cb.addItem(0,"Rome")
  CALL cb.addItem(0,"Copenhague")
END FUNCTION

PUBLIC FUNCTION cb_init_2(cb)
  DEFINE cb ui.ComboBox
  CALL cb.clear()
  IF with_undef THEN
     CALL cb.addItem(0,"<undef>")
  END IF
  CALL cb.addItem(0,"Berlin")
  CALL cb.addItem(0,"Berne")
  CALL cb.addItem(0,"Madrid")
  CALL cb.addItem(0,"Vienne")
END FUNCTION