Navigation:  Reference > Commands >

Trap

Print this Topic Previous pageReturn to chapter overviewNext page

 

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 - sacGOSUB / 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.

 

labelRequired 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 NAMEWhat it does

 

F1 - F10Executes trap if user presses key
SF1 - SF10Executes trap if user presses SHIFT & key
CTL_F1-CTL_F10Executes trap if user presses CTRL & key
ALT_F1-ALT_F10Executes 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_UPExecutes trap if user presses CTRL & Page Up key
CTL_PG_DNExecutes trap if user presses CTRL & Page Down key
CTL_HOMEExecutes trap if user presses CTRL & Home key
CTL_ENDExecutes trap if user presses CTRL & End key
CTL_A - CTL_ZExecutes trap if user presses CTRL & key
ALT_A - ALT_ZExecutes trap if user presses ALT & key
ESCExecutes trap if user presses Escape key
UPARExecutes trap if user presses up arrow (^) key
DNARExecutes trap if user presses down arrow key
LT_AExecutes trap if user presses left arrow  (<-) key
RT_AExecutes trap if user presses right arrow        (->) key
HOMEExecutes trap if user presses HOME key
ENDExecutes trap if user presses END key
PG_UPExecutes trap if user presses Page Up key
PG_DNExecutes trap if user presses Page Down key
INSRTExecutes trap if user presses Insert key
DEL_KEYExecutes trap if user presses DEL or Delete key
WD_LTExecutes trap if user presses the CTRL (control) and left arrow (<-) keys at the same time
WD_RTExecutes trap if user presses the CTRL (control) and right arrow (->) keys at the same time
TABExecutes trap if user presses the TAB key
BCK_TABExecutes trap if user presses the SHIFT and TAB key at the same time

 

RSRCHExecutes 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.

 

RLCKExecutes 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_KEYExecutes trap if user press the ENTER key.

 

MOUSE_MOVExecutes trap if the user moves the mouse.  Updates the mouse x/y coordinates.
MOUSE_LBDExecutes trap if the user presses the left button down on the mouse.  Updates the mouse x/y coordinates.
MOUSE_LBUExecutes trap if the user releases the left button on the mouse after it's been pressed down.  Updates the mouse x/y coordinates.
MOUSE_RBDExecutes trap if the user presses the right button down on the mouse.  Updates the mouse x/y coordinates.
MOUSE_RBUExecutes 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

 


Page url: http://www.cassoftware.com/tas/manual/trap.htm