Step 2 Make the Reusable Part Useful

VLF Windows Application Development

Step 2. Make the Reusable Part Useful

VFW072 – Create a Department Dropdown Reusable Part

In this step you will extend your reusable part, so that it can interact with another reusable part or form which uses it.

  • To do this you will add/publish a new event which will be signaled when the department selected in the Combo box changes.
  • You will also add/publish a property based on DEPTMENT. (That is, with Class(#Department). When this property is set, it will execute a property routine to re-position the Combo box. When another component "gets" the property, the Department Dropdown reusable part will return the current value of DEPTMENT .

1.  Define an event, named uDepartmentChanged.

Define_Evt Name(uDepartmentChanged)

 

User defined events, properties and methods in these exercises have a naming policy starting with u. You may want to implement some similar policy, which makes it easy for other developers to quickly identify the features that they may be interested in using.

2.  Create an ItemGotFocus event handling routine for the Combo box. Add logic to signal the uDepartmentChanged event.

     Also add code to signal this event at the end of the Combo box Initialize event. When this component is used in a "New Employee" command handler for example, the application will be able to initialize its department code, by handling this event.

Evtroutine Handling(#CMBX_1.ItemGotFocus) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
Signal Event(uDepartmentChanged)
Endroutine

 

3.  Define a property uCurrDepartment. It should handle Get, by returning the current value of DEPTMENT. It should handle Set, by executing a SetDept property routine.

Define_Pty Name(uCurrDepartment) Get(*auto #deptment) Set(SetDept)

 

     Note: the editor will highlight this code as having an error, until you have created the property routine.

4.  Create a property routine, named SetDept.

a.  Define a map, for input, with a class of DEPTMENT, named #SetDept. A property routine must have one input or output parameter. In this case the routine receives DEPTMENT as SetDept and will reposition the combo box.

     Your code should look like the following:

Ptyroutine Name(SetDept)
Define_Map For(*input) Class(#deptment) Name(#SetDept)
Endroutine

 

b.  Add logic to read through the combo box entries, using SELECTLIST/ENDSELECT.

     Leave when DEPTMENT equals SETDEPT.

     Then set focus for the combo box current item.

     Your code should now look like:

Ptyroutine Name(SetDept)
Define_Map For(*input) Class(#deptment) Name(#setdept)
Selectlist Named(#CMBX_1)
Leave If(#deptment = #setdept)
Endselect
#CMBX_1.currentItem.focus := true
Endroutine

 

5.  Compile your department dropdown reusable part.