Step 3 Create a Prompt Form for Employee Number

VLF Windows Application Development

Step 3. Create a Prompt Form for Employee Number

VFW102 – Field Visualizations in a Grid

In this step you will create an employee prompt form, change the iiiEMPNO field definition and configure the employee number column to use the prompter form.

1.  Create a new Form / Basic Form:

     Name: iiiVFW26

     Description: Employee Prompt

     The prompter form will display a list of all employees and return Employee number for the selected employee.

     The list entry is highlighted if a valid employee number was entered in the input field.

2.  Copy and paste the following code to replace the new form's initial code. Ignore errors initially. The form uses a reusable part which you will create in the next step.

Function Options(*DIRECT) 
 
BEGIN_COM ROLE(*EXTENDS #PRIM_FORM) DEFAULTPTY(P_EMPLOYEE_NUMBER) CLIENTHEIGHT(422) CLIENTWIDTH(392) FORMSTYLE(Owned) HEIGHT(456) LEFT(759) TOP(200) WIDTH(400)
 
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_1) CAPTION('All Employees ') DISPLAYPOSITION(1) HEIGHT(417) LAYOUTMANAGER(#LAYOUT1) LEFT(0) PARENT(#COM_OWNER) TABPOSITION(1) TABSTOP(False) TOP(0) WIDTH(385)
 
DEFINE_COM CLASS(#PRIM_LTVW) NAME(#LISTVIEW) COLUMNBUTTONHEIGHT(31) DISPLAYPOSITION(1) FULLROWSELECT(True) HEIGHT(356) LEFT(6) PARENT(#GPBX_1) SELECTIONSTYLE(Single) TABPOSITION(1) TOP(15) WIDTH(373)
 
DEFINE_COM CLASS(#PRIM_LVCL) NAME(#LVCL_3) DISPLAYPOSITION(1) PARENT(#LISTVIEW) SOURCE(#EMPNO) WIDTH(23)
 
DEFINE_COM CLASS(#PRIM_ATLM) NAME(#LAYOUT1)
 
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#IL301) ATTACHMENT(Center) MANAGE(#LISTVIEW) MARGINBOTTOM(2) MARGINLEFT(2) MARGINRIGHT(2) MARGINTOP(2) PARENT(#LAYOUT1)
 
DEFINE_COM CLASS(#PRIM_PANL) NAME(#PANL_1) DISPLAYPOSITION(2) HEIGHT(40) LEFT(4) PARENT(#GPBX_1) TABPOSITION(2) TABSTOP(False) TOP(373) WIDTH(377)
 
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_1) ATTACHMENT(Bottom) MANAGE(#PANL_1) PARENT(#LAYOUT1)
 
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PB_OK) BUTTONDEFAULT(True) CAPTION('&OK') DISPLAYPOSITION(1) LEFT(288) PARENT(#PANL_1) TABPOSITION(1) TOP(8)
 
DEFINE_COM CLASS(#PRIM_LVCL) NAME(#LVCL_1) DISPLAYPOSITION(2) PARENT(#LISTVIEW) SOURCE(#FULLNAME) WIDTH(56) WIDTHTYPE(Remainder)
 
Define_Pty Name(P_EMPLOYEE_NUMBER) Get(get_empno) Set(SET_EMPNO)
 
DEFINE_COM CLASS(#iiiVFW26) NAME(#Collections) scope(*Application)
 
* search and Set Focus on first employee entry
Ptyroutine Name(SET_EMPNO)
Define_Map For(*INPUT) Class(#EMPNO) Name(#EMPLOYEE)
Define_Com Class(#empno) Name(#wempno)
#std_num := #EMPLOYEE.value.CurSize
#wempno := #EMPLOYEE.value
 
for each(#entry) in(#Collections.Employees)
#wempno := #entry.value.Substring( 1 #std_num )
 
#empno := #entry.value
#fullname := #Collections.Fullnames<#empno>
Add_Entry To_List(#LISTVIEW)
#LISTVIEW.Currentitem.Image <= #VI_EMPLOY
 
* select current employee
If ('#employee = #wempno')
set #listview.CurrentItem selected(true)
Endif
endfor
 
Endroutine
 
Ptyroutine Name(get_empno)
Define_Map For(*output) Class(#EMPNO) Name(#EMPLOYEE)
#EMPLOYEE := #empno
Endroutine
 
* Close Form and return result
Evtroutine Handling(#PB_OK.Click #LISTVIEW.DoubleClick)
#COM_OWNER.hideform
#COM_OWNER.Modalresult := OK
Endroutine
End_Com

 

3.  Save the form.

4.  Create a new Reusable Part / Object.

     This stores a keyed collection of employee numbers and a keyed collection of full names, keyed on EMPNO. 

     This design enables the prompt form to load the collections once, the first time it is used. Subsequent executions of the prompt form do not need to read the employee file.

     Name: iiiVFW27

     Description: Employees Collection

5.  Complete the reusable part's initial code by copy and pasting the following code:

* Keyed collections
DEFINE_COM CLASS(#PRIM_KCOL<#EMPNO #Empno>) NAME(#Employees)
DEFINE_COM CLASS(#PRIM_KCOL<#FULLNAME #EMPNO>) NAME(#Fullnames)
 
* Properties
DEFINE_PTY Employees GET(*COLLECTION #Employees)
DEFINE_PTY Fullnames GET(*COLLECTION #Fullnames)
 
* Load keyed collection with Personnel details
EVTROUTINE HANDLING(#COM_OWNER.CreateInstance) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
Select Fields(#empno #givename #surname) From_File(PSLMST)
#Employees<#Empno> := #Empno
#Fullnames<#Empno> := #Givename + ' ' + #Surname
Endselect
ENDROUTINE
 

6.  Compile the reusable part.

7.  In the editor, switch to the form, iiiVFW26 and change this line, to match your reusable part name:

DEFINE_COM CLASS(#iiiVFW26) NAME(#Collections) scope(*Application)
 

8.  Compile the form iiiVFW26.

     Note: The form contains the following event routine:

* Close Form and return result
Evtroutine Handling(#PB_OK.Click #LISTVIEW.DoubleClick)
#COM_OWNER.hideform
#COM_OWNER.Modalresult := OK
Endroutine

 

     The routine executes when the OK button is clicked or a list entry is double clicked.

     The Com_Owner.ModalResult := OK informs the calling field that the prompter is being closed successfully and it should retrieve the value of the default property containing the selected employee number.

9.  Open the field iiiEMPNO in the editor. Select the Visualization tab and click the Insert Prompter Form toolbar button. In the Repository Find dialog, select your prompter form iiiVFW26 and click OK.

10. Select the VisualEdit component and use the Details tab to change its ShowPrompter property to True. Note that the VisualEdit visualization now shows a prompter button.

11. Save and close the field definition.

12. Open the Resources for a Section reusable part (iiiVFW25) in the editor and select the Design view.

13. Select the Code column (iiiEMPNO). The column should already have a ReadOnly property of  False.

     Make the following changes:

Property

Value

EditorPart

iiiVFW25

DisplayAppearance

Edit

EditAppearance

Edit

 

14. Re-compile the reusable part.

15. Execute the Framework and select the Resources command handler for a section.

     When you click in the employee number column (Code) a prompt button will now be shown.

16. Click the prompt button to run the prompt form. Note that the employee number for this row is selected in the list.

17. Select a new employee number and click OK or double click the entry. The form closes and the column entry is updated.

This reusable part prompter visualization can also be used on a form or panel.