Advanced Enter Key Handling in VL applications

Visual LANSA Framework

Advanced Enter Key Handling in VL applications

The Enter key is often used to indicate the initiation of some activity (eg: to perform a search, to save an update, etc) in VL applications.

Typically the ButtonDefault() property is used on push buttons such as "Search" or "Save" so that the Enter key causes a virtual click event to be issued against the button.

In complex VL forms containing many different reusable parts the use of the ButtonDefault() property may become problematic for two reasons:

  • Only a single button can be the default at any point in time on a Windows form.
  • There is no ability to use program logic to decide what the Enter key actually means and how it should be handled in different contexts. 

The most powerful solution to handling the Enter key differently in different places on complex forms is be solved by using the KeyPress event. This allows the VL program to specifically trap the Enter key and then respond to it in different ways.

Consider the following modifications made to the logic in the filter DF_FILT1 example shipped with the VLF.

1. No button has ButtonDefault() specified

This prevents any confusion about which button the Enter key should be directed to.

 

2. The user may initiate an Employee name search in two ways

 

Evtroutine Handling(#Surname.KeyPress) Keycode(#KeyCode)

 

if ('#KeyCode.Value = Enter')

 

If *SEARCHOK

   Execute Search

Else

   Use Message_box_show (ok ok Error *Component 'Enter a search name') 

Endif

 

Endif

 

Endroutine

 

*

* Search button pressed

*

 

Evtroutine Handling(#Search_phbn.Click)

 

Execute Search

 

Endroutine

 

The first event routine handles the use of the Enter key within the Surname field. If the user presses Enter then either a search is performed or an error message is displayed (Condition *SEARCHOK is true if field #Surname is non-blank).

The second routine handles a specific click of the Search button.

Both routines share a common SEARCH subroutine to perform the search logic.

Note that where multiple fields (or other visual controls) are used you can handle them all through a single routine like this: 

  

Evtroutine Handling(#Surname.KeyPress #GiveName.KeyPress #ComboBox1.KeyPress etc etc)

           Keycode(#KeyCode)