Step 4 Ensure Details displayed for first Employee

VLF Windows Application Development

Step 4. Ensure Details displayed for first Employee

VFW122 – Launching a VLF Window

As explained in Step 3. Change Employee Details Command Handler, the second window must be open in order to process the uShowWindowCompleted method. This means your initial avShowWindow in Employee Images for Section command handler will not be processed, except to open the new window III_EMP.

Bear in mind that this is simply an exercise that illustrates how to programmatically show a command in a new window. However, as mentioned earlier, a user could simple use the framework's Windows menu to open the Employees business object in a new window, and manually access the required employee details.

For example:

The following solution uses a timer component to invoke an avShowWindow to open a new framework window and then, after a short delay, invoke avShowWindow again so that the details for the first employee selection are displayed.

1.  With Employee Images for a Section open in the editor, on the Design tab, drag a timer component onto the panel. The Timer is a non-visual component and will not be displayed in the Design view.

Define_Com Class(#PRIM_TIMR) Name(#TIMR_1)

 

2.  Select the above line and press F7 to display the Details tab for the Timer. Change its Interval property to 0. The timer will initially not be started.

Define_Com Class(#PRIM_TIMR) Name(#TIMR_1) Interval(0)

 

3.  Create a NewWin method routine:

a.Move all the code from the uOpenEmpWindow event routine to the NewWin method routine.

b.In the NewWin method routine delete this line:

#empno := #i_empno

Your NewWin routine should now look like the following:

Mthroutine Name(NewWin)
* define a temporary class #VF_SY154 reference
Define_Com Class(#vf_sy154) Name(#window) Reference(*dynamic)
* Ask the framework manager to locate a window by name and return a reference
#window <= #avFRAMEWORKMANAGER.avWindow<'III_EMP'>
* True if second window is open
If (#Window *IsNot *Null)
Message Msgtxt('Window III_EMP is already open')
* Display employee details in III_EMP window
#AvFrameworkManager.avShowWindow Caller(#Com_Owner) For(BUSINESSOBJECT) Oftype(EMPLOYEES) Windowname(III_EMP) Execute(DETAILS) Openinfo1(#EMPNO)
* Second window needs to be opened and called again after a short delay
Else
* Open a new VLF window and start timer
#AvFrameworkManager.avShowWindow Caller(#Com_Owner) For(BUSINESSOBJECT) Oftype(EMPLOYEES) Windowname(III_EMP) Execute(DETAILS) 
Endif
* Free VF_SY154 reference
#window <= *null
Endroutine

 

4.Change the NewWin method routine:

a.Add OpenInfo1(OPEN) to the second avShowWindow line.

b.In the Else logic, set the Timer Interval to 2000. This will start the timer with a tick event every 2 seconds.

Your new code should look like the following. New code is highlighted:

. . . .

Else
* Open a new VLF window and start timer
#AvFrameworkManager.avShowWindow Caller(#Com_Owner) For(BUSINESSOBJECT) Oftype(EMPLOYEES) Windowname(III_EMP) Execute(DETAILS)  OpenInfo1(OPEN)

#TIMR_1.Interval := 2000
Endif

5.Save your changes.

6.Complete the uOpenEmpWindow event routine:

a.Change Empno to i_Empno

b.Invoke the NewWin routine

Your code should look like the following:

Evtroutine Handling(#ImageCollection<>.uOpenempwindow) Uempnum(#i_empno)

#empno := #i_empno

* Open employee details in a new framework window

#com_owner.NewWin

Endroutine

5.  Review the NewWin method routine logic.

  • Create a temporary reference to VF_SY154, named Windows
  • Check if window III_EMP exists and then:
  • Message "Window is already open"
  • Invoke avShowWindow for business object EMPLOYEES, command handler DETAILS, in window III_EMPNO and passing EMPNO as OpenInfo1()
  • Else
  • Invoke avShowWindow for business object EMPLOYEES, command handler DETAILS in window III_EMP and pass OPEN as OpenInfo1().
  • Message "Window will open shortly"
  • Set Timer Interval property to 2000.
  • Set Window to null

7.  Add the following event handling routine for the Timer Tick:

Evtroutine Handling(#timr_1.tick)
#std_count += 1
If (#std_count = 2)
#com_owner.NewWin
#timr_1.stop
Endif
Endroutine

 

     The Timer is set to an tick interval of 2 seconds (Interval(2000)). This routine will give a delay of 4 seconds , which on a modern PC will ensure the second window is running before a second request is made to show the selected employee. You may need to adjust the TIMR_1.Tick event to allow for a slower PC.

8.  Compile the Employee Images for a Section command handler.

9.  Execute your framework. Select a Department / Section with employees having images and use the pop-up menu Open Employee Details Window. The new framework window will be displayed and after a short delay, the correct details for the selected employee should be displayed.