Application.OnEndSession := @OnEndSessionApp;
procedure TForm1.OnEndSessionApp(Sender: TObject);begin TForm1.Close;end;