Futurebasic/Language/Reference/on edit
ON EDIT
[edit | edit source]Statement
[edit | edit source](+) Appearance (+) Standard Console
Syntax
[edit | edit source]ON EDIT {FN userFunction|GOSUB{lineNumber|"stmtLabel"}}
Description
[edit | edit source]This statement designates a particular function or subroutine as an edit-event handling routine. An edit-event handling routine is called in response to a keypress, if there is an active editable edit field in the current output window. After such a keypress event occurs, FB does not call your designated routine immediately. Instead, your program continues executing until the next HANDLEEVENTS statement is reached; at that time, FB calls your designated routine once for each keypress event that occurred. FB calls your routine without displaying the new character in the edit field. Your edit-event handling routine should examine the TEKEY$ function to determine which key was pressed. To apply that character (or some other character of your choice) to the edit field, your routine should execute the TEKEY$ statement. If you have not designated any edit-event handling routine, then HANDLEEVENTS applies the keypress directly to the current edit field. The most common use for an edit-event handling routine is to inhibit or alter the display of certain kinds of characters in the edit field. In most cases, you will want the following keys to be processed normally:
- CHR$(8) (delete)
- CHR$(28) (left arrow)
- CHR$(29) (right arrow)
- CHR$(30) (up arrow)
- CHR$(31) (down arrow)
- CHR$(13) (Return (if edit field type allows Return's))
Example
[edit | edit source]This program limits the entered contents of the edit field to a number of not more than four digits. DEF FN DoEdit '(prototype)
WINDOW 1 TEXT _sysFont, 12 EDIT FIELD 1,"",(10,10)-(100,30),_framedNoCR ON EDIT FN DoEdit DO ÊÊÊHANDLEEVENTS UNTIL _false END '---------- LOCAL FN DoEdit theKey$ = TEKEY$ efID = WINDOW(_efNum) SELECT CASE theKey$ CASE "0","1","2","3","4","5","6","7","8","9" LONG IF LEN(EDIT$(efID)) < 4 TEKEY$ = theKey$ 'display the digit XELSE BEEP 'Too many digits! END IF CASE CHR$(8),CHR$(28),CHR$(29),CHR$(30),CHR$(31) TEKEY$ = theKey$ 'Apply the cursor movement CASE ELSE BEEP 'Illegal character! END SELECT END FN
Note: If you use the ON EDIT FN userFunction syntax, then userFunction must refer to a function which was defined or prototyped at an earlier location in the source code. Your edit-event handling function should not take any parameters, nor return a result. The following kinds of keypresses do not trigger a call to your edit-event handling routine:
- Menu Command-key equivalents;
- -period;
- Arrow keys in a direction that the insertion point can't move (these generate DIALOG events instead);
- Modifier keys (e.g. Shift, Control, etc.) by themselves.
If there is no active editable edit field in the current window or if you are running under the Appearance Compliant runtime, keypresses are treated as DIALOG events (see the _evKey event in the DIALOG function).