alt+f4会触动sys_command消息。
所以可以这么写代码:
TForm1 = class
...
    procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
end;procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
  if Msg.CmdType <> SC_CLOSE then
    inherited
end;