I have some code placed after "Application.Run;" which is normally run when the app shuts down. This point is never reached however when the user reboots or shuts Windows down.
Can this be solved without capturing WM_ENDSESSION? (and not involving any form, I'd like the code to remain after application.run at the end of the dpr)
VCL already listens for WM_ENDSESSION
(the hidden application window), and terminates the application when the session is ending. You can add a terminate procedure in the .dpr (or elsewhere) which will be called among possible other terminate procedures:
program Project1;
uses
Vcl.Forms,
sysutils,
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
function OnTerminate: Boolean;
begin
Result := True;
// do some short work
end;
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm2, Form2);
AddTerminateProc(OnTerminate);
Application.Run;
end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With