Event Handling versus Action Handling
Event Handling versus Action Handling
Older Event Handling
The following code illustrates an older method for handling user interface events.
form input
…
case
when Event.EventType = “accelerator” and Event.EventName = “F24” % Ctrl+F4
window close MyWindow
break
when Event.EventType = “MenuItem” and Event.MenuItemTag = “Exit”
window close MyWindow
break
when Event.EventType = “FormField” and Event.EventName = “Click” and \
Event.FieldTag = “Exit”
window close MyWindow
break
…
endcase
This code illustrates a situation that is particularly common in Windows where the user can request the same action in several different ways. In this case, users could press Ctrl+F4, select the Exit menu item, or select the Exit push button.
Using the Framework Event/Action Handling
The Framework provides the ability to define mappings between specific user interface events and action names. The Framework also provides a number of standard mappings. Using the pGetAction program, we rewrite this code as follows (vlStatus, vlAction, and vlTargetWindow are assumed to be local variables):
pGetAction (vlStatus, “MyWindow”, vlAction, vlTargetWindow)
…
case
when vlAction = “Exit”
window close MyWindow
break
…
endcase
Now the code is completely independent of the actual user interface events that caused the specific actions and is also simplified. In fact, because the standard event/action mappings also map the window close event to the Exit action, that event also causes the window to be closed down. This specific event was omitted (in error) from the original version of the code which is another good reason for using pGetAction.