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.
As usual, the manuals don't seem to be any help.
Cheers,
Duncan Rance
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
Of course one has to ask why are you pressing Cntl-C randomly anyway???
Rob Vorbroker Phone: 513/583-9888
Vorbroker Consulting FAX: 513/583-9932
www.vorbroker.com ro...@vorbroker.com
Duncan Rance wrote in message <364ABFCD...@lucent.com>...
>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.
>
>As usual, the manuals don't seem to be any help.
>
>Cheers,
>Duncan Rance
> Of course one has to ask why are you pressing Cntl-C randomly anyway???
I'm not pressing it randomly. I want to use it to cancel input into the
current form - not to exit the program!
Thanks for the info on DEFER INTERRUPT though, obviously I should have
known to look up 'DEFER' when trying to work out cancel-key functionality.
Duncan
Dennis has your answer as to the proper ways to do what you REALLY want,
ie to trap ^C as a cancel key. Just one thing to add, you can also
add 'ON KEY INTERRUPT' or 'COMMAND KEY INTERRUPT' to your DISPLAY,
INPUT and MENU blocks to prevent the ^C from blowing you out of the
INPUT/DISPLAY/MENU block and just handle the key (which handling may be
to just exit the block anyway but it is more graceful and documents the
code's behavior better going forward).
Art S. Kagel
Let's not get testy Duncan. Robert's question was ill phrased - but we
are all trying to help each other here. This list is a no flame zone.
Art S. Kagel