At this stage, the departments reusable part is not that useful. It can display a list of departments and lets the user choose one, but nothing is done with the result. You actually need the reusable part to be able to:
Since all LANSA components have a standard property, event and method interface you will have to make your reusable part perform these required state changes and activities via these interfaces.
A single property named uCurrDepartment and a single event named uDepartmentChanged will do the job.
Implement the uDepartmentChanged Event
1. Edit the reusable part so that whenever focus changes in the combo box it signals the uDepartmentChanged event. Define the event like this:
define_evt uDepartmentChanged help('This event is signaled when the department selection is changed')
2. Signal the event like this:
Implement the uCurrDepartment Property
Edit the reusable part to define property named uCurrDepartment which:
1. To do this you need to define the property like this:
define_pty name(uCurrDepartment) get(*auto #deptment) set(SetDepartment)
2. And then add the property SetDepartment property routine like this:
define_map for(*input) class(#deptment) name(#sdeptment)
continue if('#deptment *ne #sdeptment.Value')
set #ComboBox.CurrentItem Focus(True)
3. Compile the new version of your reusable part.
Use the New Properties and Events in your Form
1. Edit the test form so that when details of employee are fetched you need to tell the reusable part to show the details of the new department by adding a single line like this:
Set #II_RVP29A uCurrDepartment(#deptment)
You also need to monitor for changes in the visual component. Whenever it signals uDepartmentSelected event you need to change the value of field #DEPTMENT using a routine like this:
Change #deptment #II_RVP29A.uCurrDepartment
2. Finally, you should make field #DEPTMENT on your form Read-Only(True) so that it cannot be changed via the user interface. In reality you would not normally even put field #DEPTMENT onto the form, but for purposes of this exercise it is useful because it allows you to see what is going on.
3. Recompile the test form.
4. Test your new version of the form. You should find that the reusable part switches to the correct department whenever you fetch details of an employee, and then whenever you select a department in the combo box that the value is instantly reflected in your form.