Recent

Author Topic: FormClose ignored when Windows logout  (Read 10996 times)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
FormClose ignored when Windows logout
« 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.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: FormClose ignored when Windows logout
« Reply #1 on: December 06, 2010, 01:19:32 pm »
Maybe Application.OnQueryEndSession and Application.OnEndSession can help you.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: FormClose ignored when Windows logout
« Reply #2 on: December 06, 2010, 02:35:33 pm »
Application.OnEndSession worked, thanks.

But is it intended behaviour that FormClose or FormDestroy doesn't trigger?

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: FormClose ignored when Windows logout
« Reply #3 on: December 07, 2010, 08:49:06 am »
I don't know.

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: FormClose ignored when Windows logout
« Reply #4 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).
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: FormClose ignored when Windows logout
« Reply #5 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.

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: FormClose ignored when Windows logout
« Reply #6 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 ^^
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

 

TinyPortal © 2005-2018