Step 4. Implement the Employee Image component.
VFW104 – Simple Keyed Collections
In this step you will change the
command handler (iiiVFW27) to use the new Employee Image component.1. Open iiiVFW28 in the editor.
2. Change the
definition to use #iiiVFW29 (Employee Image).Changes are highlighted in red, ignore errors at this stage.
Define_Com Class(#PRIM_KCOL<#iiivfw28 #empno>) Name(#ImageCollection) Reference(*dynamic) Style(Collection)
3. Change the
method routine:Change the
which adds an image entry to , to add the image component, .Set_Ref Com(#ImageCollection<#empno>) To(*create_as #iiivfw28)
4. Change the
, which sets the properties for the current entry, to set the employee number, filename and caption properties for the new image component:Set Com(#ImageCollection<#EMPNO>) Parent(#COM_OWNER) uFilename(#iiiempimg.filename) Displayposition(99) uCaption(#std_name) uEmpnum(#empno)
5. Add the following method to convert to proper case:
Mthroutine Name(uProperCase)
Define_Map For(*result) Class(#std_name) Name(#o_text)
Define_Map For(*input) Class(#surname) Name(#i_text)
#std_name := #i_text.lowerCase
#std_flag := #std_name.substring( 1, 1 ).upperCase
#o_text := #std_flag + #std_name.substring( 2, 19 ).trim
Endroutine
6. Retrieve Surname from the employee file and convert to proper case:
Select Fields(#empno #surname) From_File(pslmst1) With_Key(#deptment #section)
#std_name := #com_owner.uProperCase( #surname )
7. Add logic to switch to the Employee business object,
command handler when an image component signals event:Evtroutine Handling(#ImageCollection<>.uShowEmpDetails) Uempnum(#I_EMPNUM)
#empno := #I_EmpNum
* Switch to Employee / Details command handler
#avframeworkmanager.avSwitch To(BUSINESSOBJECT) Named(EMPLOYEES) Execute(DETAILS) Caller(#com_owner) Clearinstancelist(TRUE)
Endroutine
Note: The and parameters are case sensitive. Ensure that they match your Framework object names.
8. Add a VL Framework event handling routine for
which will tell the business object which instance should be displayed based on the employee number passed by the event.Note: This routine sets up the required instance list columns for Employee to invoke the .
Evtroutine Handling(#avFrameworkManager.avAddSwitchInstances) Options(*NOCLEARERRORS *NOCLEARMESSAGES) Caller(#Caller)
Define Field(#udate) Type(*char) Length(19)
* Make sure the caller is this component
If_Ref Com(#Caller) Is_Not(*Equal_to #Com_Owner)
Return
Endif
Fetch Fields(#surname #givename #deptment #salary #startdte) From_File(pslmst) With_Key(#empno)
#fullname := #surname + ', ' + #givename
#udate := #startdte.asdate( DDMMYY ).AsDisplayString( DDsMMsCCYY )
Invoke Method(#avFrameworkManager.avAddSwitchInstance) Businessobjecttype(EMPLOYEES) Visualid1(#EMPNO) Visualid2(#fullname) Acolumn1(#deptment) Ncolumn1(#salary) Dcolumn1(#udate) Akey1(#EMPNO)
Endroutine
The
event routine is always executed immediately after you execute a switch using the method. This event allows you to control what data will be placed in the instance list of the target business object. The component signalling this event is passed in the Caller parameter.It is important to only execute the code in this event if the component that signalled this event is the component itself. Therefore you should return from this event routine if the caller is not equal to #com_owner. Notice how the
is used to compare the and . You must use this syntax due to the fact that you are comparing the component itself and not a simple string.The
method specifies what data to add in the target instance list.If required, you could call the
method repeatedly, to place multiple entries into the target business object's instance list.9. Compile the enhanced
command handler (iiiVFW28).10. Execute the Framework. Select the
command handler for the Department and Section for which you created employee image records. Your command handler should now look like the following:
11. Double click on an employee image or right click and use the pop-up menu to
.The Framework should switch to the
command handler for the selected employee (check the surname shown).The instance list should contain an entry for this employee and the details of the employee should be displayed: