Field variable default value vs. Field Visualization Picklist default item

Fields can have a default value and the picklist for a field can have a default item. If not careful it is possible for these two values to be out of sync with each other.

For example, If you run the below form in debug mode and look at the value of #EMPSEX at the "message" command it's value is blank unless the radio button has been selected. This may appear incorrect as the field picklist has a default item but is in fact correct behavior.

What happens is the form on start up initializes the field so #EMPSEX to its default value. In this case no default value has been specified so the field variable value is blank. However, for the visualization Blank is not a valid value so the visualization initializes as per the rules of the picklist (to the value of the default item in this case)

What we have created is a case where the field default value and the field picklist default items value are out of sync. To resolve this #EMPSEX should be defined with a default value of 'M'. Field and Visualization will then be in sync and the field value will match the visualized appearance 

To avoid confusion it is recommended that a field default value be set to the value of the default item in the field's picklist.

Form Source

FUNCTION OPTIONS(*DIRECT)

BEGIN_COM ROLE(*EXTENDS #PRIM_FORM) CLIENTHEIGHT(306) CLIENTWIDTH(492) LEFT(326) TOP(162)

DEFINE_COM CLASS(#EMPSEX.Visual) NAME(#EMPSEX) DISPLAYPOSITION(1) LEFT(40) PARENT(#COM_OWNER) TABPOSITION(1) TOP(40)

DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_1) CAPTION('Save') DISPLAYPOSITION(2) LEFT(53) PARENT(#COM_OWNER) TABPOSITION(2) TOP(192)

EVTROUTINE handling(#com_owner.Initialize)

SET #com_owner caption(*component_desc)

ENDROUTINE

EVTROUTINE HANDLING(#PHBN_1.Click)

message 'Field Sex has a Value?'

ENDROUTINE

END_COM

Field Source ( EMPSEX Alpha(1) )

BEGIN_COM ROLE(*EXTENDS #PRIM_OBJT)

BEGIN_COM ROLE(*Visual #PRIM_EVEF) NAME(#VisualEdit) HEIGHT(19) USEPICKLIST(False) WIDTH(178)

END_COM

* Define Picklist Visualization

BEGIN_COM ROLE(*Visual #PRIM_EVPL) NAME(#PICKLIST) DEFAULTVISUAL(True) HEIGHT(44) MARGINLEFT(50) WIDTH(167)

End_Com

* Define the Picklist

BEGIN_COM ROLE(*picklist) NAME(#LIST)

DEFINE_COM CLASS(#PRIM_PKIT) NAME(#ITEM1) CAPTION('Male') DEFAULT(True) PARENT(#LIST) VALUE('M')

DEFINE_COM CLASS(#PRIM_PKIT) NAME(#ITEM2) CAPTION('Female') PARENT(#LIST) VALUE('F')

End_Com

BEGIN_COM ROLE(*Visual #PRIM_EVPL) NAME(#Dropdown) APPEARANCE(DropDownList) HEIGHT(69) WIDTH(209)

END_COM

END_COM