Board index » delphi » Closing Modal windows by pressing F12

Closing Modal windows by pressing F12

I've made a TAction with shortcut F12 and with the following code as it's
onExecute:
Screen.ActiveForm.Close;

This closes the current active window of my application whenever the user
presses F12. But for some reason it only works when the window has been
opened by the show command. When opening a window using showmodal, nothing
happens when the user tries to close it again by pressing F12.

Why is that?

regards

Jimmy

 

Re:Closing Modal windows by pressing F12


Quote
Jimmy Rasmussen wrote in message

<3c1ccd02$0$330$ba624...@nntp02.dk.telia.net>...

Quote

>I've made a TAction with shortcut F12 and with the following code as it's
>onExecute:
>Screen.ActiveForm.Close;

>This closes the current active window of my application whenever the user
>presses F12. But for some reason it only works when the window has been
>opened by the show command. When opening a window using showmodal, nothing
>happens when the user tries to close it again by pressing F12.

>Why is that?

Good question. I'm not sure.

The help file says "to close a modal form, set its ModalResult
to a non-zero value". It doesn't come out and say that's the
_only_ way, though. Maybe you're finding out that it is. Do you
have the VCL source? It would have the definitive answer.

In the end, it's an implementation detail.

Groetjes,
Maarten Wiltink

Re:Closing Modal windows by pressing F12


ModalResult := mrOK;

The above assignment will close a modalwindow, and return the value mrOK.

You can use it, to return a simple status of the code running in the modal
window (ie cancel, error, OK ...)

Usage example:

if SomeForm.ShowModal=mrOK then
  ...
else
  ...

JP

Quote
"Jimmy Rasmussen" <Jim...@get2net.dk> wrote in message

news:3c1ccd02$0$330$ba624c82@nntp02.dk.telia.net...
Quote

> I've made a TAction with shortcut F12 and with the following code as it's
> onExecute:
> Screen.ActiveForm.Close;

> This closes the current active window of my application whenever the user
> presses F12. But for some reason it only works when the window has been
> opened by the show command. When opening a window using showmodal, nothing
> happens when the user tries to close it again by pressing F12.

> Why is that?

> regards

> Jimmy

Other Threads