Thanks,
Mark Haliday
-Steve-
"Mark Haliday" <markh...@yahoo.com> wrote in message
news:3a1c0044$1_2@dnews...
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)
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!