I have a small program which simply reads a diary text file and displays it in a memo - thats it - no buttons you double click on the form to shut it down if you want it to disappear. When it has been run (even if you close it) windows XP gets as far as "Windows is shutting down" ie. after "Saving User Settings" etc and then it hangs. I have examined the code which appears little different from other programs I have written which were much more complicate but can see nothing wrong - the close routine for example contains application.terminate which (I think) should clear anything wrong out of memory anyway. Any ideas since I seem to have run out of them?
Just a few suggestions, because it is not entirely clear what your problem is.
Does your application has problems with closing, or does it hang during windows shutdown?
- Have you tried putting a breakpoint on application.Terminate? And does that provide extra information.
- From within the mainform, you can use Close and not Application.Terminate.
Apps can inhibit shutdown if they are using up CPU time, although a 'modern' OS like Vista and W7 should show a dialog telling you about this after a period and offering to let you abort the app. Check that your app is showing 0% CPU when its idle by looking in task manager and viewing 'processes'. Bri
Based on what you've described, the program should have a single line of programmer-added code, which is to call Memo1.Lines.LoadFromFile
. That's what it means when you say, "That's it."
That program doesn't even need a "close routine." (I assume you mean the form's OnClose
event.) When the main form closes, the application terminates itself automatically. That's how all Delphi programs work. If you're putting more on top of that, you're doing too much.
The following code reacts on the windows shutdown message und closes the program.
TForm1 = class(TForm)
...
private
procedure WMEndSession(var Message: TWMEndSession); message WM_ENDSESSION;
...
end;
procedure TForm1.WMEndSession(var Message: TWMEndSession);
begin
close;
end;