Messagedlg在Delphi xe7 android中

问题描述 投票:2回答:1

我只是试图在安装Delphi xe7,android平台上的MessageAlerts时执行一个示例,遗憾的是它无法正常工作,它给出了以下错误消息:

阻止此平台中未实现的对话框

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;

任何想法如何解决?

android delphi firemonkey delphi-xe7
1个回答
20
投票

这在XE7发行说明中有解释:

Dialog Box Methods Support Anonymous Methods to Handle Their Closing

在XE6中,对对话框方法(InputBox,InputQuery,MessageDlg,ShowMessage)的调用始终是阻塞的。在对话框关闭之前,不会执行调用其中一个方法之后的任何代码。 Android不允许阻止对话框,因此您无法在Android上使用这些方法。

在XE7上,InputBox,InputQuery和MessageDlg支持新的可选参数ACloseDialogProc。包含此新参数的调用适用于所有平台,包括Android。这个新的可选参数允许您提供在对话框关闭时调用的匿名方法。使用此新参数调用这些方法时,您的呼叫将在桌面平台中阻止,在移动平台中无阻塞。如果在关闭对话框后需要执行代码,请使用此新参数以确保应用程序在所有支持的平台上按预期工作。

...

ShowMessage在XE7中也获得了对Android的支持,对ShowMessage的调用在桌面平台上是阻塞的,在移动平台上是非阻塞的。但是,ShowMessage不提供任何新参数来处理其关闭。如果需要在ShowMessage显示的对话框关闭后执行代码,请使用MessageDlg而不是ShowMessage。

例如:

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;
© www.soinside.com 2019 - 2024. All rights reserved.