FormClose ignored when Windows logout lazarus / 34-Windows ---------------------------------------------------------------------- User137 · 2010-12-05 23:16 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 · 2010-12-06 12:19 Maybe Application.OnQueryEndSession and Application.OnEndSession can help you. ---------------------------------------------------------------------- User137 · 2010-12-06 13:35 Application.OnEndSession worked, thanks. But is it intended behaviour that FormClose or FormDestroy doesn't trigger? ---------------------------------------------------------------------- Vincent Snijders · 2010-12-07 07:49 I don't know. ---------------------------------------------------------------------- fabienwang · 2011-01-04 08:50 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). ---------------------------------------------------------------------- User137 · 2011-01-04 12:12 Tested with Delphi7, log looks like this: Code: [Select]closequery called! So it doesn't execute onClose either... weird. ---------------------------------------------------------------------- fabienwang · 2011-01-04 13:21 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 ^^