Re: 4GL: Cancel Key
Posted in 1998
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
In article <364ABFCD.A394E838@lucent.com>, Duncan Rance <drance@lucent.com> wrote: > Hi, > > I'm fairly new to 4GL and I'm using some examples from '4GL by Example' to help > write a small application. > > The problem is that when I press control-c to cancel when in a form, the whole > thing bombs out. I am using ACCEPT KEY RETURN in OPTIONS, but I need something > that does CANCEL KEY ESCAPE. > The reason control-c is bombing is because your Unix operating system is trapping it and posting an interrupt signal to the application. You can do one of two things to prevent this: 1) Use the documented DEFER INTERRUPT instruction in your MAIN function. Now when you're in and INPUT, INPUT ARRAY, PROMPT, or CONSTRUCT statement and type the interrupt key (in your current case, CTRL+C), the program will set a global (and documented) variable, int_flag to TRUE, and exit the control block you're in. You can check int_flag after the END INPUT (etc) statement to see how the user exited, with interrupt or your ACCEPT key. 2) You can reset the interrupt signal at the Unix level with a (documented in the Unix manuals) stty command. stty intr ^? is what I usually used, which on most terminals and emulation packages is a CTRL+BKSP. You can experiment at the Unix shell level by setting stty intr to something, then type the "who" command and type the interrupt key combination you set. If the command is canceled and you're back to the command prompt, you've got it. These two things can be used in combination, of course. I can't recommend setting the INTERRUPT signal to escape, however, since most function keys send a signal beginning with escape and if you have interrupt set to escape, and function key sent will send an interrupt. You can, however, still use ESCAPE to be your cancel key, if you can't talk people out of it; it just takes a little more code. As you've done already, set OPTIONS ACCEPT KEY to something other than the default of ESCAPE. Do set DEFER INTERRUPT, and then in every place you gather user input: ON KEY (ESC) LET int_flag = TRUE EXIT INPUT Or, for menus: COMMAND KEY (ESC) LET int_flag = TRUE EXIT MENU Then test int_flag after the control block. Remember to reset int_flag to FALSE, the program doesn't do it for you. Do I wish there were a more application-wide way to doing this, instead of writing those three nagging lines of code? Yes. Do I consider it a major flaw in 4GL? No. It's just the tool showing its Unix (as opposed to MS DOS) roots. > As usual, the manuals don't seem to be any help. > It was there, just not where you expected it (the story of most manual failure). I'd suggest attending the 4GL class; this is all covered on day 1. Dennis J Pimple Informix Software, Inc. Denver, CO, USA -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own