在VCL下,常用的询问对话框包括
procedure TfrmMainVCL.btnAppMessageboxClick(Sender: TObject); begin if Application.MessageBox('是否退出?', '询问', MB_YESNO + MB_ICONQUESTION) = IDYES then begin Close; end; end;
或者是:
uses System.UITypes; procedure TfrmMainVCL.btnMessageDlgClick(Sender: TObject); begin if MessageDlg('是否退出?', mtConfirmation, [mbYes, mbNo], -1) = mrYes then begin Close; end; end;
在FMX下,Application不再有MessageBox函数,只能使用MessageDlg函数,写法如下:
procedure TfrmMain.btncloseClick(Sender: TObject); begin if MessageDlg('是否退出?', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], -1) = mrYes then Close; end;