Lazarus

Programming => Operating Systems => Windows => Topic started by: User137 on December 06, 2010, 12:16:52 am

Title: FormClose ignored when Windows logout
Post by: User137 on December 06, 2010, 12:16:52 am
I have application that has to write settings in a file when it quits. This works properly when i manually close it, but when i logout or shutdown computer, nothing is saved.

So far i have tried it in formClose and formDestroy events and also in the application command flow after the line Application.Run;

Windows 7 32bit.
Title: Re: FormClose ignored when Windows logout
Post by: Vincent Snijders on December 06, 2010, 01:19:32 pm
Maybe Application.OnQueryEndSession and Application.OnEndSession can help you.
Title: Re: FormClose ignored when Windows logout
Post by: User137 on December 06, 2010, 02:35:33 pm
Application.OnEndSession worked, thanks.

But is it intended behaviour that FormClose or FormDestroy doesn't trigger?
Title: Re: FormClose ignored when Windows logout
Post by: Vincent Snijders on December 07, 2010, 08:49:06 am
I don't know.
Title: Re: FormClose ignored when Windows logout
Post by: fabienwang on January 04, 2011, 09:50:36 am
I just did a simple test:

Code: [Select]
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  Memo1.Lines.Add('close called!');
  Memo1.Lines.SaveToFile('console.log');
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
  Memo1.Lines.Add('closequery called!');
  Memo1.Lines.SaveToFile('console.log');
end;

Both aren't called when a user logoff on Windows or when the computer Shutdown.
The callbacks should be bind to CloseQuery and Close events automatically in my opinion.
(If someone can try this on a Delphi and tell us the result).
Title: Re: FormClose ignored when Windows logout
Post by: User137 on January 04, 2011, 01:12:23 pm
Tested with Delphi7, log looks like this:
Code: [Select]
closequery called!
So it doesn't execute onClose either... weird.
Title: Re: FormClose ignored when Windows logout
Post by: fabienwang on January 04, 2011, 02:21:52 pm
weird
in CloseQuery method you have a CanClose boolean, it's default value is True
so the Close should be called.
Try to see if CanClose is true or false.

But as Vincent said, we need to use Application.OnQueryEndSession and Application.OnEndSession.
In my opinion, there is something missing. Application QueryEndSession and EndSession should call the main form Close events, whatever if the user or the system closes the application.
But at least we have a way to make it work ^^
TinyPortal © 2005-2018