version 6.0
WR ON EVENT (area; event; method)
| Parameter | Type | Description | |
| area | Longint | 4D Write area | |
| event | Longint | Event code | |
| method | String | Method to execute |
Description
The WR ON EVENT command installs method as the method to be called whenever the event described by event occurs in area. Events are passed directly to method before being handled by 4D Write.
If area equals 0, method becomes the default event method for all 4D Write areas until the database is closed. If an area has a specific event method installed, that method is called instead of the default.
The following table lists the possible values for event:
When called, method receives six parameters that describe the state of area at the time of the event. You must explicitly type these parameters using compiler directives. The following table describes the parameters received by method:
$1 returns the long integer that is the area ID where the event took place. $2, $3, and $4 describe whether a specific modifier key was depressed at the time of the event. If the value equals 0, the key was not pressed. If the value equals 1, the key was pressed. $5 returns the event type. $6 varies depending on the type of event.
Method Variables and the Event Parameter ($6)
If event equals 0, $6 returns the ASCII code of the key calling the event.
If event equals 1 or 2, $6 indicates whether you single- or double-clicked a reference. If $6 equals 0, no reference was selected. If $6 equals 1, a reference was selected. method can be called if you perform one of the following actions:
Single- or double-click a reference
Right-click (on Windows) or Control-click (on Mac OS).
On Mac OS, pressing the Control key while clicking typically displays a pop-up menu. On Windows, right-clicking typically displays a drop-down menu.
If event equals 5, $6 describes whether or not the area is activated. If $6 equals 0, the 4D Write area is deactivated. If $6 equals 1, the 4D Write area is activated.
If event equals 7 and the print job is a mail merge, $6 indicates the table number for the table used. If the print job is not a mail merge, $6 equals 0.
If event equals 9, $6 indicates where margins have been reset in the document. If $6 equals 0, the margins have been reset in the body. If $6 equals 1, the margins have been reset in the header. If $6 equals 2, the margins have been reset in the footer.
To filter characters, you must use method as a function that returns 0 or 1. This enables you to specify characters in the document that 4D Write will ignore.
Initialize $0 to 1 to make the method trap a particular event. Initialize $0 to 0 if you do not want to trap a particular event. For example, if you do not want the character "@" to appear in your document, filter all characters appearing in the document. If the $6 variable is equal to the ASCII code of the "@" character, you initialize $0 to 1 and ignore it.
Note: If you filter all characters, operations may slow down considerably since the method will be called for each keystroke.
Example
In the following examples, some actions are executed depending on the type of event:
`Form method: If (Form event=On load) WR ON EVENT (Area;0;"ProcName") `Call for all key strokes WR ON EVENT (Area;5;"ProcName") `Check for area status DISABLE MENU ITEM(2;1) `Disable menu item "Change font" End if
`ProcName method: Case of : ($5=0) `Intercepts the key strokes If ($6=199) | ($6=200) `ASCII codes corresponding BEEP $0:=1 Else `Leave the event to 4D Write $0:=0 End if : ($5=5) `Intercept change in status of area If ($6=0) `If the area is inactive DISABLE MENU ITEM(2;1) Else ENABLE MENU ITEM(2;1) End if End case
See Also
WR Get on event method, WR ON ERROR.