This command is used to set internal traps so that if a certain key is pressed the program will take an appropriate action.
TRAP trap_name_list - sac Required - The name of the trap. These are listed below. You may include multiple trap names for a single trap command. Each of the traps will be set to the same values. This is generally used when you are setting a group of traps to IGNR (ignore) or DFLT (default).
do_what - sac | GOSUB / DFLT - Required - The options are: DFLT - Default; don't call a subroutine when the user presses that key (or key combination). GOSUB - transfer control to the line label indicated (typically the beginning of a subroutine) when the user presses that key; you need to make sure the routine is terminated with a RET. |
IGNR / RET_FALSE / RET_TRUE - These options apply to the RLCK (Record Lock) trap only. The trap is checked if a record the user is trying to read is locked by another user. IGNR - The user will receive a message the record is locked and will remain in a loop until the record becomes available. RET_FALSE - The trap will return a value of .FALSE. to the locking routine which will immediate exit the search loop and return the value of 84 (record locked) or 85 (file locked) in the FLERR() function. RET_TRUE - The trap will return a value of .TRUE. to the locking routine and the search loop will execute again. This would be the equivalent of setting the trap to IGNR except that the user won't even get a message that the record is locked.
label | Required if GOSUB is specified. You must specify the label name so the program will know where to transfer control. |
COMMENTS
Traps are event driven rather than process commands. Nothing actually happens when the command is executed until the appropriate key is pressed or the action occurs. By setting a TRAP you a doing the equivalent of specifying a ShortCut property in a TMenuItem object without having to create it.
NOTE: When the TRAP command is executed the program sets a flag in the active form that tells it to watch the keys being entered on that form. So, if you set a TRAP in the program it will only be effective when the form that is currently active remains active. If you load a different form that TRAP (or group of traps) will no longer be active until you return to the previous form. This is also true if you load a temporary form and set a trap while that form is loaded. Once you exit from that form the trap will no longer be active. HOWEVER, if you turn on the watching process by specifying a single TRAP ALL the traps currently active, will be active for the new form also. Due to this, you should use the XTRAP command to set the group of traps to the appropriate DO_WHAT option before loading a new form and reset them after the form exits.
NOTE: In several of the form objects that allow user entry you can set traps (KeyTraps) that are specific to that object. This has the same effect as though you set the traps in program code without having to actually write that code. This is a very quick and easy way to add TRAPs to your program and are the preferable method instead of using the actual command. However, the RLCK and RSRCH traps cannot be set this way.
The traps available are:
TRAP NAME | What it does |
F1 - F10 | Executes trap if user presses key |
SF1 - SF10 | Executes trap if user presses SHIFT & key |
CTL_F1-CTL_F10 | Executes trap if user presses CTRL & key |
ALT_F1-ALT_F10 | Executes trap if user presses ALT & key |
NOTE: ALT-F4 Has been disabled since this is a command in Windows(R) to close a window. We have trapped this so that this can not happen since you could have processes going that could cause data corruption as of 11/07/07
CTL_PG_UP | Executes trap if user presses CTRL & Page Up key |
CTL_PG_DN | Executes trap if user presses CTRL & Page Down key |
CTL_HOME | Executes trap if user presses CTRL & Home key |
CTL_END | Executes trap if user presses CTRL & End key |
CTL_A - CTL_Z | Executes trap if user presses CTRL & key |
ALT_A - ALT_Z | Executes trap if user presses ALT & key |
ESC | Executes trap if user presses Escape key |
UPAR | Executes trap if user presses up arrow (^) key |
DNAR | Executes trap if user presses down arrow key |
LT_A | Executes trap if user presses left arrow (<-) key |
RT_A | Executes trap if user presses right arrow (->) key |
HOME | Executes trap if user presses HOME key |
END | Executes trap if user presses END key |
PG_UP | Executes trap if user presses Page Up key |
PG_DN | Executes trap if user presses Page Down key |
INSRT | Executes trap if user presses Insert key |
DEL_KEY | Executes trap if user presses DEL or Delete key |
WD_LT | Executes trap if user presses the CTRL (control) and left arrow (<-) keys at the same time |
WD_RT | Executes trap if user presses the CTRL (control) and right arrow (->) keys at the same time |
TAB | Executes trap if user presses the TAB key |
BCK_TAB | Executes trap if user presses the SHIFT and TAB key at the same time |
RSRCH | Executes trap when a record is read from any file. Use the LAST_FILE() function in connection with this trap to determine which file was accessed. |
RLCK | Executes trap when a record to be read is locked by another user. See IGRN / RET_FALSE / RET_TRUE options above for additional do_what options for this trap. You can also use the GOSUB option. In that case you need to return .TRUE. (stay in the search loop) or .FALSE. (exit from the search loop). If you don't return a value it defaults to .TRUE. If this trap is set the user will not receive any messages about the record being locked unless you display one. |
L_EXIT Executes trap if record is locked and user answers N (No) no system's offer to retry. See below. The L_EXIT trap works in the following manner: if the user tries to access a record that is locked and gets the system message about retrying and answers No (N), this trap will be executed. The only option that applies is the GOTO option. If that option is set, when the user answers N, the system will transfer control to the label specified in the command.
ENTER_KEY | Executes trap if user press the ENTER key. |
MOUSE_MOV | Executes trap if the user moves the mouse. Updates the mouse x/y coordinates. |
MOUSE_LBD | Executes trap if the user presses the left button down on the mouse. Updates the mouse x/y coordinates. |
MOUSE_LBU | Executes trap if the user releases the left button on the mouse after it's been pressed down. Updates the mouse x/y coordinates. |
MOUSE_RBD | Executes trap if the user presses the right button down on the mouse. Updates the mouse x/y coordinates. |
MOUSE_RBU | Executes trap if the user releases the right button on the mouse after it's been pressed down. Updates the mouse x/y coordinates. |
NOTE: See Mouse_Row() and Mouse_Col() to retrieve the mouse coordinates
EXAMPLE
You can see an example of this command in action in the WTASFLOC.SRC program.
EXAMPLE2
start:
trap F1 gosub 'mnihelp.click'
ret
mnihelp.click:
WHELP xpath()*'TAS7docs.chm'
ret