Page 1 of 1
How to detect the close of form window
Posted: Fri Mar 13, 2015 12:38 pm
by manumart1
Is it possible to detect the event "the user closing the window of a form" (red X in upper right corner)?
I would like to cleanup variables of the module (they may have many information not needed anymore).
When the user open the form again I initialize variables via menu:
"StdCmds.OpenAuxDialog('Priv/Rsrc/A', 'Test'); PrivA.Init()".
If not, is it possible to open the window of the form, with the close button disabled; I would put my own ad hoc button to cleanup and then call "StdCmds.CloseDialog".
Thank you,
Manuel
Re: How to detect the close of form window
Posted: Fri Mar 13, 2015 12:59 pm
by cfbsoftware
There was a discussion titled
How to disable the window close button started on the Oberon microsystems mailing list on 19th Jun 2014. Although the aim was different to yours I think there should be enough information there to enable you to do what you are trying to do.
Unfortunately the archives at
http://blackboxframework.org/archive/ only go up to Sep 2013. However, I have attached a zipped copy of the emails involved in the discussion.
Re: How to detect the close of form window
Posted: Fri Mar 13, 2015 1:40 pm
by manumart1
Many thanks, Chris.
I will look at your attached code, it seems very interesting.
Finally, I found a way to detect the closing of the window. It is explained in
Sql Developer Manual (Sql/Docu/Dev-Man), paragraphs
Determining whether the window should be closed and
Cleaning up when the window is closed:
- Via menu SQL — Insert Anchor I put a special control in the form, and link it to a any pointer variable of my module.
- That anchor control can have a Guard and a Notifier.
- The purpose of the Guard is to show a message to confirm the closing of the window. If the linked variable is not NIL and Guard puts par.disabled to TRUE then the confirm message is shown. I do not need it now.
- The Notifier is a parameterless procedure, and is tiggered when the window is closed. I will put here my cleanup code.
- The linked variable is set to NIL when finally the window is closed.
Regards
Re: How to detect the close of form window
Posted: Mon Mar 16, 2015 4:45 pm
by manumart1
For my problem it is enough to use an Anchor control. That control offers two functionalities:
- Alert to the user when he tries to close the window (and the module decides that the message is relevant, putting TRUE in par.disabled via Guard).
- Notify the module when the window is being closed (no opportunity no abort).
I only need functionality 2. For that, the Anchor control does not even need a link, only a Notifier.
Thanks to Chris, I learned another way to be notified when the user tries to close the window. I put it here just for the record:
To open the form, instead of
Code: Select all
StdCmds.OpenAuxDialog('Priv/Rsrc/A', 'Test')
you must call to the procedure OpenForm shown below:
Code: Select all
TYPE MyNotifier = POINTER TO RECORD (Sequencers.Notifier) END;
PROCEDURE (n: MyNotifier) Notify (VAR msg: Sequencers.Message);
VAR res: INTEGER;
BEGIN
WITH msg: Sequencers.CloseMsg DO
Dialog.Beep;
(*
IF ... THEN
msg.sticky := TRUE (* This avoid the closing *)
Dialog.GetOK("You can not close the window because this and this", "", "", "", {Dialog.ok}, res);
END
*)
Dialog.GetOK("Window will close ¿Sure?", "", "", "", {Dialog.yes, Dialog.no}, res);
IF res # Dialog.yes THEN
msg.sticky := TRUE (* This avoid the closing *)
END
ELSE
END
END Notify;
..
PROCEDURE OpenForm();
VAR v: Views.View; n: MyNotifier;
BEGIN
StdApi.OpenAuxDialog('Priv/Rsrc/A', 'Test', v);
NEW(n);
v.Domain().GetSequencer()(Sequencers.Sequencer).InstallNotifier(n)
END OpenForm;
When the user tries to close the window, the method Notify of n will be called, and there msg.sticky can be set to TRUE with the purpose of avoiding the closing.
Regards,
Manuel