 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Martin Schoellhammer Guest
|
Posted: Fri Feb 06, 2004 11:40 am Post subject: Delphi fails to do 'Ondestroy' when shutting down PC |
|
|
Hello,
I had D4 before and converted an application to D7. The same code
behaves other when compiled in D7: I assigned some handling in the
'Ondestroy' event (not only freeing variables) of a form. When I run
the app, and then shut down the PC (tested under Win2000) the
instructions in the Ondestroy-Event are NOT done, when the app is
compiled under D7, in D4 they are.
Is there any bugfix or workaround available?
|
|
| Back to top |
|
 |
Peter Below (TeamB) Guest
|
Posted: Fri Feb 06, 2004 7:36 pm Post subject: Re: Delphi fails to do 'Ondestroy' when shutting down PC |
|
|
In article <40236b1b.638908 (AT) newsgroups (DOT) borland.com>, Martin
Schoellhammer wrote:
| Quote: | I had D4 before and converted an application to D7. The same code
behaves other when compiled in D7: I assigned some handling in the
'Ondestroy' event (not only freeing variables) of a form. When I run
the app, and then shut down the PC (tested under Win2000) the
instructions in the Ondestroy-Event are NOT done, when the app is
compiled under D7, in D4 they are.
|
Highly unlikely IMO. The only form event that fires reliably when you
shut down Windows while your app is still running is OnCloseQuery
(because it is fired from the WM_QUERYENDSESSION message). No normal
application shutdown is performed in this case, none of the apps
objects is destroyed in a normal manner since Windows does not bother
destroying any Windows when the system goes down.
The VCL reacts to the WM_ENDSESSION message (which follows
WM_QUERYENDSESSION) by setting Application.Terminated to true. This
would make the app exit its message loop and continue with normal
closedown (which would indeed destroy the main forms and all other
objects owned by the Application object). If it ever woke up again,
that is, after receiving the message. And if it had enough time to
close down shop before Windows removes the process from memory.
| Quote: | Is there any bugfix or workaround available?
|
Do your state saving in the OnCloseQuery event.
--
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
|
|
| Back to top |
|
 |
Peter Below (TeamB) Guest
|
Posted: Tue Aug 17, 2004 3:59 pm Post subject: Re: Delphi fails to do 'Ondestroy' when shutting down PC |
|
|
In article <zenv8buompyn.yz1ddt6jvenk$.dlg (AT) 40tude (DOT) net>, Marcus Mönnig wrote:
| Quote: | I'm doing my cleanup in OnCloseQuery, but I wonder if that is in fact the
reason I'm seeing other error messages. Say, I have a TInifile that I create
in the OnCreate handler and free in the OnCloseQuery, isn't it possible that
even after OnCloseQuery is through, one of the event handlers is called and
my code accesses the just freed Tinifile?
|
Yes, that cannot be excluded. Use FreeAndNil to destroy objects, that enables
you to check the object variables for Nil before you use them. Or save the
state in OnCloseQuery and destroy the objects in OnDestroy. For a TMemInifile
saving the state would involve writing any values, then calling the UpdateFile
method. For a TInifile you can do the same, although Updatefile will not do
anything on WinNT platforms (since inifiles are not buffered by these OSes).
| Quote: | I know you said "do your *state saving* in the OnCloseQuery event" not the
cleanup, but for some objects and data structures that is the same.
|
Then separate the two functions. If not possible then take precautions against
accessing already deleted objects.
--
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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|