Google グループは Usenet の新規の投稿と購読のサポートを終了しました。過去のコンテンツは引き続き閲覧できます。
Dismiss

Close or Application.Terminate?

閲覧: 2,253 回
最初の未読メッセージにスキップ

Mark Haliday

未読、
2000/11/22 3:00:002000/11/22
To:
I have seen closing a Delphi app in a couple ways, using "Close;" and using
"Application.Terminate;". Seems to me Application.Terminate is the way to
go for new Delphi multi-form apps? Am I mistaken, or is there a better 3rd
choice that I am not seeing.

Thanks,

Mark Haliday

Steve Zimmelman

未読、
2000/11/22 3:00:002000/11/22
To:
I use Close in the application's MainForm for normal termination (the user
clicks the "exit" button). If I need to close the app somewhere else, I use
Application.Terminate.

-Steve-

"Mark Haliday" <markh...@yahoo.com> wrote in message
news:3a1c0044$1_2@dnews...

Guido Gybels

未読、
2000/11/23 3:00:002000/11/23
To:
Mark Haliday wrote in message <3a1c0044$1_2@dnews>...

>I have seen closing a Delphi app in a couple ways, using "Close;" and using
>"Application.Terminate;". Seems to me Application.Terminate is the way to
>go for new Delphi multi-form apps? Am I mistaken, or is there a better 3rd
>choice that I am not seeing.


Actually, "Close" is a method from the TForm class, where Terminate belongs
to the TApplication object. By closing the main form, you also end the
application. So, which one to use simply depends on the context. As on-line
help mentions: Terminate is not immediatly, but performs an orderly closing
down of the application (freeing objects and resources).

Guido GYBELS
Programmer (GDG GROEP BELGIUM)


Peter Below (TeamB)

未読、
2000/11/23 3:00:002000/11/23
To:
In article <3a1c0044$1_2@dnews>, Mark Haliday wrote:
> I have seen closing a Delphi app in a couple ways, using "Close;" and using
> "Application.Terminate;". Seems to me Application.Terminate is the way to
> go for new Delphi multi-form apps? Am I mistaken, or is there a better 3rd
> choice that I am not seeing.

I always use mainform.close. There are subtle differences between the ways
available to close an app, mainly in terms of the events that get fired
during the closedown sequence.

Way back in time when Delphi 1 was en vogue i ran a number of tests,
attaching handlers to OnShow, OnClose, OncloseQuery, OnDestroy etc. and
logged the execution to file. The result was this (and a quick test in D5
shows that Application.Terminate does not fire OnClosequery or OnClose as
well, so nothing seems to have changed):

Form closed via button that calls Application.Terminate:

OnShow called
Destroy called
OnHide called
OnDestroy called
-----------------
Form closed via button that calls Form1.Close, with Action:= caFree in
FormClose

OnShow called
OnCloseQuery called.
On Close called
Destroy called
OnHide called
OnDestroy called
----------------
Form closed via system menu
OnShow called
OnCloseQuery called.
On Close called
Destroy called
OnHide called
OnDestroy called
-----------------
App closed by logging off Win NT

OnShow called
OnCloseQuery called.

The OnShow is always called when the app comes up but you see that the
different ways of closing cause a different sequence of events to be called.
The most pathological case is the last one, here the form is not properly
destroyed at all! And there is no event that is called for each of these
cases. So you have to put the cleanup code into two locations, OnCloseQuery
and OnDestroy, and guard against duplicate execution.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


新着メール 0 件