28 June 2017

Bug: SysFormEnumComboBox selection method returns wrong value

The SysFormEnumComboBox class is very useful when only some of enum values must be enabled in a form, but it has a bug.

Problem description
The SysFormEnumComboBox.selection() method returns correct value only when being called after super() of form run method.
Test form is attached.
In form init method SysFormEnumComboBox is initialised with 3 enum values, Invoiced value is set as default and selection method is called:

In form run method selection method is called before and after super():

The results are:
init method, after super, SalesStatus selection is 255.
run method, before super, SalesStatus selection is 255.
run method, after super, SalesStatus selection is 3.

Hints
It appeared that FormComboBoxControl texts are set in form run method. Alternative approach must be used to get enum selection.
Solution
1. Add a new map comboBoxItem2EnumValueMap to classDeclaration:

2. Initialise and fill map in init method:

3. Use map in selection method:
The results are:
init method, after super, SalesStatus selection is 3.
run method, before super, SalesStatus selection is 3.
run method, after super, SalesStatus selection is 3.
The solution is also attached.

No comments:

Post a Comment