if MessageDlg('Close the form?', mtConfirmation,
    [mbOk, mbCancel], 0) = mrCancel then
     CanClose := False;

解决方案 »

  1.   

    例子
    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);begin
      if MessageDlg('Close the form?', mtConfirmation,
        [mbOk, mbCancel], 0) = mrCancel then
         CanClose := False;
    end;
      

  2.   

    procedure Tfrmmain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if Application.MessageBox('您确定要退出吗?','提示',MB_OKCANCEL+MB_DEFBUTTON2+MB_ICONWARNING)=IDOK then
        CanClose := True
      else
        CanClose := False;
    end;
      

  3.   

    if MessageBox(0,'是否关闭','显示',MB_OKCANCEL)=1 then
        CanClose:=true
      else
        CanClose:=false;
      inherited;