Einfach die beiden prozeduren oben in in den private-Bereich Deines Hauptformulares kopieren, Klasse vervollständigen.
Du benötigst eigentlich nur die WMEndSession.
Delphi-Quellcode:
TMyForm = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
Closed : Boolean;
procedure DoClose;
procedure WMEndSession(var Msg: TMessage); message WM_ENDSESSION;
end;
...
procedure TMyForm.FormCreate(Sender: TObject);
begin
Closed := false;
end;
procedure TMyForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DoClose;
end;
procedure TMyForm.WMEndSession(var Msg: TMessage);
begin
DoClose;
end;
procedure TMyForm.DoClose;
begin
if Closed then exit;
Closed := true;
//sonst was machen
end;