On

Command group Flag affected Reversible Execute on client Platform(s)
Events NO NO YES All

Syntax

On event-code or codes (code1,code2,...)

Description

This command is used in an event handling method and marks the beginning of a code segment that executes when the specified event (or one of a number events) is received by the current event handling method. An On command also marks the end of any preceding On statement. You specify the event or list of events using the event constants.

When Omnis generates an event it sends the event information as a series of event parameters to the appropriate event handling method. The first parameter is always an event constant. Further parameters, if any, depend on the event and further describe the event. This event information is interpreted by the On statements in the event handling methods. Window field events are sent to the $event() method behind the field, then to the $control() method for the window instance, and then to the $control() method for the current task. Events that occur in the window itself, such as a click on the window background, are sent to the class method called $event(), then to the $control() method for the current task. A particular event is sent to the first On command which applies, and when the next On command is encountered quits the method.

You should place any code which is to be executed for all events before the first On command. You cannot nest On commands or put them in an If or Else statement. You can use On default to handle any events not handled by an earlier On event command. The On commands must be in event handling methods only: if used elsewhere they are not executed. The function sys(86) at the start of a method reports any events received by the object.

See also Quit event handler.

Example

; This example shows typical event handling for a field
On evBefore
  ; code to process an evBefore event
On evAfter
  ; code to process an evAfter event
On evClick,evDoubleClick
  ; code to process both evClick and evDoubleClick events