Step 4 Implement the Employee Image component

VLF Windows Application Development

Step 4. Implement the Employee Image component.

VFW104 – Simple Keyed Collections

In this step you will change the Employee Images for Section command handler (iiiVFW27) to use the new Employee Image component.

1.  Open iiiVFW28 in the editor.

2.  Change the ImageCollection 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 uExecute method routine:

     Change the Set_Ref which adds an image entry to ImageCollection, to add the image component, iiiVFW28.

Set_Ref Com(#ImageCollection<#empno>) To(*create_as #iiivfw28)

 

4.  Change the Set, which sets the properties for the current ImageCollection 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, Details command handler when an image component signals uShowEmpDetails 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 To(), Named() and Execute() parameters are case sensitive. Ensure that they match your Framework object names.

8.  Add a VL Framework event handling routine for avAddSwitchInstances which will tell the Employees business object which instance should be displayed based on the employee number (uEmpNum) passed by the uImageClicked event.

     Note: This routine sets up the required instance list columns for Employee to invoke the avAddSwitchInstance.

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 avAddSwitchInstances event routine is always executed immediately after you execute a switch using the avSwitch 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_not(*Equal_to) is used to compare the #Caller and #Com_Owner. You must use this syntax due to the fact that you are comparing the component itself and not a simple string.

     The avAddSwitchInstance method specifies what data to add in the target instance list.

     If required, you could call the avAddSwitchInstance method repeatedly, to place multiple entries into the target business object's instance list.

9.  Compile the enhanced Employee Images for Section command handler (iiiVFW28).

10. Execute the Framework. Select the Images command handler for the Department and  Section for which you created employee image records. Your Images 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 Show Employee Details.

     The Framework should switch to the Details 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: