Posting Events vs. Calling Event Functions Directly

There is a major difference between posting an event, which will cause Vermont Views to call an event function, and calling the event function directly in your code. The difference is in the timing. Vermont Views processes events in the order in which they are placed in the queue. If there are already events in the queue when you post your event(s), those events are processed before the one(s) that you post.

As the user moves through forms, menus, and windows, Vermont Views posts internal events to allow event functions to communicate with the processing functions. For example, when the user moves to a new field on the form, Vermont Views posts events informing the form editor to leave the current field and enter a new field. Thus, you cannot depend on the event queue being empty when you post an event, and you cannot empty the queue without disrupting the processing of the current panel.

When you post an event, then, you cannot count on that event being executed immediately. In fact, you cannot count on being in the same field, or even in the same form, at the time your event is processed. If your event function depends on being in a particular field on a form, do not post an event. Instead, you should call the event function directly in your code. This allows you to have complete control over when the function is executed.

Posting an event is useful under two conditions. First, if you do not care when the event function is executed, you can post the event. Vermont Views will process the event and execute the event function when it reads that event from the queue. For example, you may wish to post an AC_KEYPRESS event to make Vermont Views think that the user pressed a particular key. This "keystroke" is processed after Vermont Views finishes whatever internal processing it is currently doing. If you post an AC_KEYPRESS event with a keycode of KEY_F2, for example, Vermont Views will display the choice list attached to the current field.

The second case where posting an event is useful is when you need to have your event function called after Vermont Views has finished performing some action. For example, suppose you want to highlight a particular character in a field after the user leaves the field. When the user leaves a field, Vermont Views redisplays that field in the inactive attribute. If you need to change something about the way that field is displayed, you will need to post an event from your end-field function. The event which will cause the field to be redisplayed has already been posted; your event function will be called after the field has been redisplayed. If you were to highlight the character in the end-field function itself, your changes would be erased when Vermont Views later redisplayed that field.

These are just a few uses for posting events. You will discover others as you write your applications.

You can post Vermont Views events, or create your own event types.


Home Contents Previous Next