Step 3. Initialize the Form

This step will add code to set up entries for the SearchType combo box and enable and disable SearchMonth and SearchSurname when a search type is selected. Search for surnames beginning or containing will be supported and search for employees with a Date of Birth in the search month.

1.  Add code to the form's CreateInstance event routine to define three entries in the SearchType combo box for "Name beginning", "Name contains" and "Search by Month". Position the combo box to the first entry. Disable SearchMonth and MonthLabel initially.

     Your code should look like the following:

Evtroutine Handling(#com_owner.CreateInstance)

 

Set Com(#com_owner) Caption(*component_desc)

Clr_List Named(#SearchType)

#std_name := 'Name beginning'

#STD_OBJ := 'BEGIN'

Add_Entry To_List(#SearchType)

#STD_NAME := 'Name contains'

#STD_OBJ := CONTAINS

Add_Entry To_List(#SearchType)

#STD_NAME := 'Search by Month'

#STD_OBJ := 'MONTH'

Add_Entry To_List(#SearchType)

Get_Entry Number(1) From_List(#SearchType)

#SearchType.CurrentItem.Focus := true

#MonthLabel.Opacity := 20

#SearchMonth.Enabled := false

 

Endroutine

2.  Add code to the SearchType.ItemGotSelection event routine to enable or disable the search values based on the field STD_OBJ. Use the Opacity property to change the appearance of the SearchLabel and SurnameLabel.

     A control's Opacity property denotes the appearance of the control in terms of its interaction with the background. The default is 100; entirely opaque. No background will be visible at all. As the value decreases, more and more of the background will become visible through the control. When the value is zero, the control will be entirely transparent and only the background will be visible.

     Your code should look like the following:

Evtroutine Handling(#SearchType.ItemGotSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)

Case (#STD_OBJ) /* search type */

When ('= BEGIN' '= CONTAINS')

#MonthLabel.Opacity := 20

#SearchMonth.enabled := false

#SurnameLabel.Opacity := 100

#SearchName.enabled := true

When (= MONTH)

#MonthLabel.opacity := 100

#SearchMonth.enabled := true

#SurnameLabel.Opacity := 20

#SearchName.enabled := false

Endcase

Endroutine

3.  Compile and test the form. Selecting search type should enable and disable the Surname and Birthday Month controls.

     Your form should look like the following: