Step 2. Make the Department / Section Dropdown Useful
VFW074 – Create a Compound Reusable Part
From the previous exercise, you know that the Departments dropdown component:
- Signals when the selected department is changed.
- Has a property which re-positions the dropdown or returns the currently selected department code.
1. Consider what functionality the new department / section component will need, to interact with your
command handler:- The first thing to recognize is that the new component is now responsible for interacting with the department dropdown component. The department dropdown component is encapsulated within the new reusable part. This means the new reusable part must handle both department and section changes.
- For example, if its current department property is changed it must:
a. Reposition the department dropdown
b. Rebuild the sections dropdown from the table SECTAB using the new department code as a key.
2. In the
view, select the department dropdown RP and create an event handling routine for . Add logic to do the following:a. Set DEPTMENT to the value of the
property of DEPT_DD.b. Signal that department has changed
c. Clear the list SECT_DD
d. Select SECTION and SECDESC from file SECTAB using DEPTMENT as key, add all entries to SECT_DD
e. Get entry 1 from SECT_DD
f. For SECT_DD, set
to current itemYour code should look like the following:
Evtroutine Handling(#DEPT_DD.UDepartmentChanged)
#deptment := #DEPT_DD.uCurrDepartment
Signal Event(uDeptChanged)
Clr_List Named(#SECT_DD)
Select Fields(#SECT_DD) From_File(sectab) With_Key(#deptment)
Add_Entry To_List(#SECT_DD)
Endselect
Get_Entry Number(1) From_List(#SECT_DD)
#SECT_DD.currentItem.focus := true
Endroutine
3. Define the following properties:
Define_Pty Name(uCurrDept) Get(GetCurrDept) Set(SetCurrDept)
Define_Pty Name(uCurrSection) Get(*auto #section) Set(SetCurrSection)
Setting or getting
will require logic in property routines.Getting
will return current value of SECTION.Setting
will require logic in a property routine.Ignore errors at this stage.
4. Define the following events:
Define_Evt Name(uSectChanged)
Define_Evt Name(uDeptChanged)
5. Create the
property routine. This needs to an output parameter based on DEPTMENT.Your code should look like the following:
Ptyroutine Name(GetCurrDept)
Define_Map For(*output) Class(#deptment) Name(#CurrDept)
Endroutine
6. The
routine needs to retrieve the current department from DEPT_DD. Add code to do this. The new code is shown in red.Ptyroutine Name(GetCurrDept)
Define_Map For(*output) Class(#deptment) Name(#CurrDept)
#CurrDept := #DEPT_DD.uCurrDepartment
Endroutine
7. Create a
property routine. It needs an input parameter based on DEPTMENT.Your code should look like the following:
Ptyroutine Name(SetCurrDept)
Define_Map For(*input) Class(#deptment) Name(#CurrDept)
Endroutine
8. The
needs to set the current department property in DEPT_DD. Add code to do this. The new code is in red.Ptyroutine Name(SetCurrDept)
Define_Map For(*input) Class(#deptment) Name(#CurrDept)
#DEPT_DD.uCurrDepartment := #CurrDept
Endroutine
9. Create a
property routine. This needs to have an input parameter based on SECTION.Your code should look like the following:
Ptyroutine Name(SetCurrSection)
Define_Map For(*input) Class(#section) Name(#CurrSect)
Endroutine
10. The
routine needs to re-position the section combo box to the input value.It does this by reading the combo box using SELECTLIST and leaving when SECTION = the input section code.
It should then set focus for current item and signal the
event.Add code to achieve this. New code is shown in red.
Ptyroutine Name(SetCurrSection)
Define_Map For(*input) Class(#section) Name(#CurrSect)
Selectlist Named(#SECT_DD)
Leave If(#section *EQ #CurrSect)
Endselect
#SECT_DD.currentItem.focus := true
Signal Event(uSectChanged)
Endroutine
11. Create an
for the sections combo box. Add logic to signal the event.Your code should look like the following:
Evtroutine Handling(#SECT_DD.ItemGotFocus) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
Signal Event(uSectChanged)
Endroutine
12. Compile your department / section combo box component.