HTBasic Help
×
Menu
Index

On Event Command (continued)

 
Description
 
The ON EVENT statement not only sets up the ON EVENT branch, but also enables theevent. For an event to cause branching, the event must be defined AND an event branch must be specified with the ON EVENT command. ON EVENT defines the event branch that is taken after the specified widget generates the specified event.
 
For example, the following line causes the program to go to the subroutine Event_handler when the SLIDER widget event CHANGED occurs (assuming @Slider is the SLIDER widget handle).
 
    ON EVENT @Slider;"CHANGED" GOSUB Event_handler
 
The most recent ON EVENT (or OFF EVENT) statement for a given widget and event combination overrides any previous ON EVENT definition for that combination. If the overriding ON EVENT definition occurs in a context different from the one in which the overridden ON EVENT occurs, the overridden ON EVENT is restored when the calling context is restored.
 
Any specified line reference for GOTO or GOSUB must be in the same context as the ON EVENT statement. CALL and GOSUB will return to the next line that would have been executed if the ON EVENT widget event had not been serviced. The system priority is restored to that which existed before the ON EVENT branch was taken.
 
RECOVER forces the program to go directly to the specified line in the context containing that ON EVENT statement. When RECOVER forces a change of context,the system priority is restored to that which existed in the original (defining) contextat the time that context was exited.
 
NOTE
 
The priority specified in the ON EVENT statement (as in all ON-event statements) must be higher than the current system priority in order for the event to be recognized.
 
When you nest ON EVENT statements, be aware that the system priority is raised to the one you specified in the ON EVENT statement, when that eventis serviced for CALL and GOSUB.
 
To ensure that the events are recognized for all of your ON EVENT statements, specify a higher priority each time you go deeper into the nesting. To do this, query for the current system priority and then increase it by one, instead of specifying the priority as a number between the event name and GOTO, GOSUB, RECOVER, or CALL.
 
Use the following command sequence within the ON EVENT statement to do this. This technique will cause an error if the current system priority is 15.)
 
         VAL(SYSTEM$("SYSTEM PRIORITY"))+1
 
CALL and RECOVER remain active when the context changes to a subprogram or function, unless the change in context is caused by a keyboard-originated call. GOSUB and GOTO remain active when the context changes to a subprogram, but the branch cannot be taken until the calling context is restored.
 
ON EVENT is disabled by DISABLE EVENT or DISABLE, is reenabled by
ENABLE EVENT or ENABLE, and is deactivated by OFF EVENT.