For completeness sake, because the form may not be in wsNormal state, you should do something like this:
interface
type
TForm1 = class(TForm)
{the normal declarations go here}
private
FSavedState: TWindowState;
end;
implementation
procedure TForm1.WMSysCommand;
begin
if (Msg.CmdType = SC_MINIMIZE) then begin
FSavedState := WindowState;
Hide; { This way it just references Self }
{
Form1.Hide; <- You should *never* do this, because one day
you *will* want to instantiate a form in other
ways, referencing through other variable.
}
end else
inherited;
end;
procedure TForm1.TrayIconClick(Sender: TObject);
begin
WindowState := FSavedState;
Show;
BringToFront;
end;
This unfortunately didn't work:
private
FSavedState: TWindowState;
procedure TForm1.WMSysCommand;
begin
if (Msg.CmdType = SC_MINIMIZE) then begin
FSavedState := WindowState;
Hide; { This way it just references Self }
//--->>>'TEMPOUT'<<<--- if (Msg.CmdType = SC_MINIMIZE) then begin
//--->>>'TEMPOUT'<<<--- Form1.Hide;
end
else
inherited;
end;
procedure TForm1.TrayIcon1Click( Sender : TObject) ;
begin
//--->>>'TEMPOUT'<<<--- self.WindowState := TWindowState.wsNormal;
//--->>>'TEMPOUT'<<<--- self.Show;
//--->>>'TEMPOUT'<<<--- self.BringToFront;
WindowState := FSavedState;
Show;
BringToFront;
end;
When you click on the tray icon, you get this and have to click on the taskbar button to get the window to appear: