>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help User

# Event Handlers

An event handler is a verb that is invoked when a Windows event occurs, for example, when a button is pressed. The standard event handling mechanism in J supports three levels of event handler for a given form. If the form name is abc, these are:

-     abc_handler

(the parent handler)

- `abc_id_class`

(e.g. `abc_pressme_button`)

- `abc_formevent`

(e.g. `abc_close`)

-     abc_default

(the default handler)

When an event occurs, the system searches for an event handler in the order given, and executes the first one it finds. Therefore, for a form `abc`:

- if a verb `abc_handler` is defined, it is executed for every event associated with that form
- if no such verb is defined, and the event is for a specific control, such as button `pressme`, then if a verb for that control such as `abc_pressme_button` is defined, it is executed;
  or if the event is a form event and a verb for that event is defined, such as `abc_close`, then it is executed
- if no such verb is defined, then if `abc_default` is defined, it is executed
- if no event handler verb is found, the event is ignored

  Typically, most forms will be written using only the second level of event handler. The other two levels allow the programmer to deal easily with special cases.

  We can try this out on the form defined above. First define a default handler:

         mywin_default=: wdinfo bind 'this is the default'

  Click on the form to give it focus, then try pressing a function key. Each time, this new default event handler will be executed. However, when you press on the button, its own event handler is executed.

  Now try defining a parent handler:

         mywin_handler=: wdinfo bind 'this handles all events'

  Once this is defined, it handles all events from the form.

  Note that these event handlers are ordinary verbs and can be defined and modified as required. The search for an appropriate event handler takes place at the time the event occurs. For example, delete the parent handler:

         erase 'mywin_handler'
      1

  Now the other event handlers will again be used to respond to the form's events.

>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help User