
A short article to accompany the "Metronome" program.
Modern software development systems rely heavily on programs being able to respond to events which happen "outside" the program, somehere in the computer system in which the program is running. Examples of events could be a mouse button being clicked while the program is active, or a clock running past a particular time, or a "message" being received from another program, or a printer timeout error.
The MS-Windows 95, 98 and NT operating systems have lists of "standard events" to which programs are expected to be able to respond. Here are some of them, in the notation used by the "Delphi" programming language, an object-oriented event-handling form of Pascal:
Mouse Events:
Keyboard Events:
As you can see, events are quite small things, like the releasing of a key on the keyboard perhaps. There are very many of them, and part of the difficulty of learning an event-oriented program language is the problem of finding out which event or events your program needs to respond to, and how.
Event-driven programming systems are especially useful in programming for multi-tasking operating systems such as 32-bit Windows, Unix, Mac-OS, RISC-OS and so on. Programs for these operating systems need to be able to co-exist with many other programs sharing the same processor, memory, hard drive and other resources. This co-existence can be either "co-operative", in which each program politely asks all the others before claiming any more of the shared resources, or "pre-emptive", in which the program which is currently active grabs all the resources it needs and shuts the other programs out until it has done what it needs to do. Either way, multi-tasking programs need to be able to exchange information with each other. To do this they use "messaging systems" - when a program wants to send information to be picked up by another program, the first program generates an event of its own, to which the other programs can respond. Such events are sometimes referred to as "software interrupts" because they behave rather like the "hardware interrupts" generated by peripheral devices.
UniCOMAL and Events
The UniCOMAL development system is DOS-based, single-tasking, and does not expect to find itself having to co-operate with other programs. Nonetheless, it is possible to use it to demonstrate some of the simpler aspects of event handling.
Timer events
UniCOMAL V3.11 Developers' comes with two experimental library modules called "Unitimer" and "Timers". Both of them allow UniCOMAL programs to handle events generated by the computer system's real-time clock.
UniTimer is a small, simple example that can be used to demonstrate event handling and to serve as a template for a more complicated module. The module can only handle one timer, so priority handling cannot be demonstrated by this module.
The module "Timers", located in the file: TIMERS.EXE in the Modules directory of a full installation of V3.11 Developers, is an enhancement of the UniTimer module. It is able to control any number of simultaneously active timers, each able to generate an event with some interval. Practical programming has shown that a program often need to have more than one timer running at the same time. This module was developed to meet this need. There is no helpfile available for "timers", but it is well described in the text file "Timers.rme", which can be found in the "Supp" directory of your COMAL directory, along with three very simple example programs called "Timer1.cml", "Timer2.cml" and "Timer3.cml". A more ambitious example, called "Metronom.cml", can be found in the file "metronom.zip" in the downloads section of this site.
Mouse events
The "Buttons" module, also in the downloads section, although not strictly speaking event-driven, provides a straightforward way to simulate mouse-event-driven programming. Buttons is now in Version 2.0, which copes with left-, middle- and right- mouse button clicks, and comes with a variety of example programs which demonstrate the use of a polling loop to intercept and handle mouse events. The most ambitious of these programs is a simple implementation of a Minesweeper game, called "Minehunt.cml". As well as demonstrating mouse button event handling, it also uses a single seconds timer showing the use of the Unitimer module.
Updated 31-12-1999