Hello.
I need to save some data before my application exits. I do that in
FormDestroy. But this approach works fine when I close my application via menu (handler just invokes
Application.Terminate) or with the window button. It doesn't work when user reboot/turn off computer.
I also tried
Self.OnExit := @Self.OnExitHandler; // code is copied from FormDestroy and FormDestroy is cleaned
but it doesn't work at all (even via menu) for me as well as
Application.AddOnEndSessionHandler(@Self.OnExitHandler);
My question: what is the right way to save state on application exit? As I understand, before reboot/shutdown OS asks an app to close, why the handler with
FormDestroy doesn't work then? And what
Form.OnExit and
Application.AddOnEndSessionHandler are supposed to do (and when, because they wasn't invoked in my app)?
I tried it on Windows XP and 7. Lazarus 1.6.4, FPC 3.0.2
Thanks for help.