I\'m having Tray application.
Onj FormCloseQuery I check if program should goto tray and instead of closing it I put it in tray (CanClose := False)
But if Wi
Your problems stem from the use of OnCloseQuery which is the wrong event to be using. Remy's answer explains how to workaround Windows shutdown being blocked by the default VCL end session message handling. And this in turn is caused by setting CanClose to False in the OnCloseQuery event.
That workaround will get the job done but there's a much simpler way to deal with this.
Instead of stopping the form from closing, let it go ahead and close. Remove your OnCloseQuery event altogether. Replace it with an OnClose event.
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caNone;
Visible := False;
end;
This rather trivial bit of code is enough to make your app minimize to the tray when the main form is closed.