Search code examples
delphifiremonkey

why MessageDlg show only "OK" button under windows?


With delphi 10.2.2 firemonkey, under windows, when i do :

MessageDlg('Are you sure you want to undo the last operation ?', // const AMessage: string;
             TMsgDlgType.mtConfirmation, // const ADialogType: TMsgDlgType;
             [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbCancel], // const AButtons: TMsgDlgButtons;
             0, // const AHelpContext: THelpContext;
             TMsgDlgBtn.mbCancel, // const ADefaultButton: TMsgDlgBtn;
             procedure(const AResult: TModalResult)
             begin
               if AResult = mrYes then begin
               end;
             end); // const ACloseDialogProc: TInputCloseDialogProc);

then only a "OK" button is show in the popup dialog (no "cancel" nor "yes"). Is it normal or I miss something ?


Solution

  • It happens because Delphi checks valid button combinations and for the combination of Yes and Cancel there's no corresponding dialog box type on Windows platform. That you get just dialog with the OK button is because the structure passed to the Windows API function is zeroed at the beginning and the value of the uType parameter MB_OK is just 0.

    The Windows implementation of this is inside the TFMXDialogService.MessageDialog method, within the FMX.Dialogs.Win module.