Messagedlg in Delphi xe7 android

2019-01-20 14:01发布

问题:

I m just trying to execute a sample given during the installation of Delphi xe7, the MessageAlerts on android platform, unfortunately it does not working, it gives the following error message:

Blocking Dialogs not implemented in this platform

procedure TMessageAlertsForm.btnMultiButtonAlertClick(Sender: TObject);
begin
  { Show a multiple-button alert that triggers different code blocks according to
    your input }
  case MessageDlg('Choose a button:', System.UITypes.TMsgDlgType.mtInformation,
    [
      System.UITypes.TMsgDlgBtn.mbYes,
      System.UITypes.TMsgDlgBtn.mbNo,
      System.UITypes.TMsgDlgBtn.mbCancel
    ], 0) of
    { Detect which button was pushed and show a different message }
    mrYES:
      ShowMessage('You chose Yes');
    mrNo:
      ShowMessage('You chose No');
    mrCancel:
      ShowMessage('You chose Cancel');
  end;
end;

Any idea How to solve it?

回答1:

This is explained in the XE7 release notes:

Dialog Box Methods Support Anonymous Methods to Handle Their Closing

In XE6, calls to dialog box methods (InputBox, InputQuery, MessageDlg, ShowMessage) were always blocking. Any code after a call to one of these methods is not executed until the dialog box closes. Android does not allow blocking dialog boxes, so you could not use these methods on Android.

On XE7, InputBox, InputQuery, and MessageDlg support a new optional parameter, ACloseDialogProc. Calls that include this new parameter work on all platforms, including Android. This new optional parameter allows you to provide an anonymous method that is called when the dialog box closes. When you call these methods using this new parameter, your call is blocking in desktop platforms and non-blocking in mobile platforms. If you need to execute code after your dialog box closes, use this new parameter to ensure that your application works as expected on all supported platforms.

...

ShowMessage also gained support for Android in XE7, and calls to ShowMessage are blocking on desktop platforms and non-blocking on mobile platforms. However, ShowMessage does not provide any new parameter to handle its closing. If you need to execute code after the dialog box that ShowMessage shows closes, use MessageDlg instead of ShowMessage.

For example:

procedure TMessageAlertsForm.btnMultiButtonAlertClick(Sender: TObject);
begin
  MessageDlg('Choose a button:', System.UITypes.TMsgDlgType.mtInformation,
    [
      System.UITypes.TMsgDlgBtn.mbYes,
      System.UITypes.TMsgDlgBtn.mbNo,
      System.UITypes.TMsgDlgBtn.mbCancel
    ], 0,
    procedure(const AResult: System.UITypes.TModalResult)
    begin
      case AResult of
        mrYES:
          ShowMessage('You chose Yes');
        mrNo:
          ShowMessage('You chose No');
        mrCancel:
          ShowMessage('You chose Cancel');
      end;
    end);
  end;
end;