| Search Locate Previous Next | Contents |
In Windows, this is where the action is! The most fundamental conceptual change you need to make when you first move from a mainframe or DOS-based environment is from a procedural approach to an event-based view of programming. The Event-Action table is where the vast majority of your APL code is called from.
It has four columns, specifying:
In the Event Name column you may use the familiar short codes from Causeway shareware (such as DC for Double-Click), the full Dyalog event name (such as Select) or the event number, e.g. 40 would be the same as GF or GotFocus. Use the numbers to handle custom events like 3005 which your application may queue on the object.
Note that you can execute more than one APL expression on any given event by entering several lines in the table the event code will repeat downwards automatically against any non-blank entries. You can either use this to avoid diamonds (by listing several expressions against the same event) or to write rule-based code where you use the condition to check for the state of some variable and fire code accordingly. For any particular event, the lines in the table execute in the order they appear in the table.
Use the right-mouse button over the row numbers to insert new rows, or to copy/move existing rows. You can also use the right-mouse over the column titles to sort the table by event code.
Running Code when Events Occur
If the condition evaluates to anything other than zero, the corresponding code will run, for example
SL: ½vec : Analyse vec
will execute Analyse vec for the non-empty case.
The simplest case is probably an Action Button, for example to select all the data in a scrolling list, you might find:
SL: :sel¼1½data : sel
When a Select event occurs on the button, your APL fragment runs, updating the variable sel (very likely a local variable on the form see Locals) and hollering its name. Assuming you have set the list to refresh on a change to this variable, it will immediately select all the rows it is displaying.
Accessing the Event Argument</h3
Supposing you want to track the mouse position on a Backcloth, perhaps to put up extra information about the cell under the pointer. You clearly need to get at the event message, and this is provided for you as ¾ (omega). You might write an action such as:
MM: :posn¾[1 2] © Record mouse row/col:posn
Similarly, to register the name of a dropped object (say a label was thrown into the wastebasket):
DD: :Delete_object 1¾
Accessing the Object Name
The name of the object which received the event is always available to you as ¸ (alpha), for example to set a label to show todays date on creation:
CR: :¸ Do 'Caption' (#.cal_disp TS)
Note the use of (del) as a shortcode for #.CPro. in the code shown above. This is optional, but has the advantage that if you relocate or rename the CPro namespace (for example to SE) you will not need to change any application code to have the new location substituted correctly.
If you will need to run lots of commands against an object, it is often handy to catch its internal name when it is created, and keep this as a local variable on the form:
CR: :pbar¸ © record name of progress bar
Rejecting Events
Of course, not all events can be rejected! The kind of things you could reject would be keystrokes in an edit field, say to allow only the characters 01(234) 56-789 in a telephone number:
KP:~(3¾)¹'()- 0123456789': Reject
You may call #.CPro.Reject to reject the event the default is always to accept it. Another common use would be to reject a users request to close the main application (accidents can happen) if the return from a #.Win.Ask is 0, indicating <No> was pressed:
CL: 0=#.Win.Ask 'OK to quit application?' : #.CPro.Reject
Note that you put this action on a special Close Request event, not against Destroy this is to allow you to attach a different set of actions to a Destroy, to be run when the form is definitely closing.
Note that if you reject an event, none of the names in the Notify column will be broadcast, and processing of the event table stops at this point.
Editing Functions and Variables from this Table
Note that you may double-click on any variable (or function) name mentioned in the condition or action columns to open an edit window on the object. If you try to open the editor on a non-existent object the designer will offer you the choice of a Function or a vector of text vectors. You can also press <F2> as an alternative to double-clicking on the name.