Board index » delphi » How to close all forms except main form programatically?

How to close all forms except main form programatically?

Hi everybody,

Is that possible?
Including all possibly open MessageForms, Dialogs etc.?

Thanks in advance
Arno Garrels

 

Re:How to close all forms except main form programatically?


Maybe you could use Screen.Forms[I] and close each one of them. Ofcourse,
you can exclude the main form. I beleive Scree.Forms includes even dialogs.

For more info see "TScreen" object in help.

HTH,
Vikram

Quote
"Arno Garrels" <arno.garr...@gmx.de> wrote in message

news:aiedif$98d$07$1@news.t-online.com...
Quote
> Hi everybody,

> Is that possible?
> Including all possibly open MessageForms, Dialogs etc.?

> Thanks in advance
> Arno Garrels

Re:How to close all forms except main form programatically?


On Fri, 2 Aug 2002 18:58:20 +0200, "Arno Garrels"

Quote
<arno.garr...@gmx.de> wrote:
>Is that possible?
>Including all possibly open MessageForms, Dialogs etc.?

Just loop over TScreen.Forms and call Close() for each form.

HTH
ain

Re:How to close all forms except main form programatically?


Vikram and Ain,

Thanks a lot it works with dialogs and message forms as well.

Arno

<Ain Valtin> schrieb im Newsbeitrag
news:3d4ac16a.3221491880@newsgroups.borland.com...

Quote
> On Fri, 2 Aug 2002 18:58:20 +0200, "Arno Garrels"
> <arno.garr...@gmx.de> wrote:

> >Is that possible?
> >Including all possibly open MessageForms, Dialogs etc.?

> Just loop over TScreen.Forms and call Close() for each form.

> HTH
> ain

Re:How to close all forms except main form programatically?


Vikram and Ain,

Thanks a lot it works with dialogs and message forms as well.

Arno

<Ain Valtin> schrieb im Newsbeitrag
news:3d4ac16a.3221491880@newsgroups.borland.com...

Quote
> On Fri, 2 Aug 2002 18:58:20 +0200, "Arno Garrels"
> <arno.garr...@gmx.de> wrote:

> >Is that possible?
> >Including all possibly open MessageForms, Dialogs etc.?

> Just loop over TScreen.Forms and call Close() for each form.

> HTH
> ain

Re:How to close all forms except main form programatically?


Vikram and Ain,

Thanks a lot it works with dialogs and message forms as well.

Arno

"Vikram Kulkarni" <vik...@captools.com> schrieb im Newsbeitrag
news:3d4ac1c7$1_1@dnews...

Quote
> Maybe you could use Screen.Forms[I] and close each one of them. Ofcourse,
> you can exclude the main form. I beleive Scree.Forms includes even
dialogs.

> For more info see "TScreen" object in help.

> HTH,
> Vikram

> "Arno Garrels" <arno.garr...@gmx.de> wrote in message
> news:aiedif$98d$07$1@news.t-online.com...
> > Hi everybody,

> > Is that possible?
> > Including all possibly open MessageForms, Dialogs etc.?

> > Thanks in advance
> > Arno Garrels

Re:How to close all forms except main form programatically?


Vikram and Ain,

Thanks a lot it works with dialogs and message forms as well.

Arno

"Vikram Kulkarni" <vik...@captools.com> schrieb im Newsbeitrag
news:3d4ac1c7$1_1@dnews...

Quote
> Maybe you could use Screen.Forms[I] and close each one of them. Ofcourse,
> you can exclude the main form. I beleive Scree.Forms includes even
dialogs.

> For more info see "TScreen" object in help.

> HTH,
> Vikram

> "Arno Garrels" <arno.garr...@gmx.de> wrote in message
> news:aiedif$98d$07$1@news.t-online.com...
> > Hi everybody,

> > Is that possible?
> > Including all possibly open MessageForms, Dialogs etc.?

> > Thanks in advance
> > Arno Garrels

Re:How to close all forms except main form programatically?


Quote
In article <aiedif$98d$0...@news.t-online.com>, Arno Garrels wrote:
> Is that possible?
> Including all possibly open MessageForms, Dialogs etc.?

In principle, yes. You can iterate over Screen.forms and call Close for all forms
other than the main one. The whole problem is from where you want to do it. If a
modal form is up the program is stuck in the modal message loop inside ShowModal, so
there is no place (other than perhaps a timer or a secondary thread) that would
execute some code.

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Re:How to close all forms except main form programatically?


"Peter Below (TeamB)" schrieb:

Quote
> In principle, yes. You can iterate over Screen.forms and call Close for all forms
> other than the main one. The whole problem is from where you want to do it. If a
> modal form is up the program is stuck in the modal message loop inside ShowModal, so
> there is no place (other than perhaps a timer or a secondary thread) that would
> execute some code.

Of course ShowModal runs a messages loop, using
Application.HandleMessages. The Delphi application will happily execute
any message sent or posted to any of its windows.

-Michael

Re:How to close all forms except main form programatically?


Quote
"Michael Winter" wrote:
> Of course ShowModal runs a messages loop, using
> Application.HandleMessages. The Delphi application will happily execute
> any message sent or posted to any of its windows.

Yes, but method Close of an underlying window is happily ignored.

Arno

Re:How to close all forms except main form programatically?


Quote
"Peter Below (TeamB)" wrote:
> In principle, yes. You can iterate over Screen.forms and call Close for
all forms
> other than the main one. The whole problem is from where you want to do
it. If a
> modal form is up the program is stuck in the modal message loop inside
ShowModal, so
> there is no place (other than perhaps a timer or a secondary thread) that
would
> execute some code.

Thanks Peter,

My app. needs to react on a "server down" event and "Screen.FormCount" seems
to enumerate all open forms in the right order to call Close. What I had to
do was just handling the mrCancel result of some MessageDlgs.

Arno

Re:How to close all forms except main form programatically?


Quote
In article <3d4af2f9_2@dnews>, Michael Winter wrote:
> Of course ShowModal runs a messages loop, using
> Application.HandleMessages. The Delphi application will happily execute
> any message sent or posted to any of its windows.

And from where would you post or send such a message?
--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Re:How to close all forms except main form programatically?


"Peter Below (TeamB)" schrieb:

Quote
> And from where would you post or send such a message?

Hotkey, device change, power broadcast, mouse move, even simply a button
on that modal form. There can be a lot of reasons. Arno didn't told us.

-Michael

Other Threads