调用按钮单击消息对话框 (mrYes)

Calling a button click on Message Dialog (mrYes)

不太确定我做错了什么,但我正在使用 Delphi XE8 组装一个 android 应用程序。

在某个时候出现消息对话框并且用户选择“是”时,我希望它调用应用程序中已有的按钮 OnClick 事件。

按钮在按下时加载相机。

我认为它是正确的,但它不起作用:

 if MessageDlg ('Do you wish to continue?', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo],0) = mrYes then
   begin
     TakeImageClick(self);
   end;

单步执行代码我没有收到任何错误,但它完全跳过了按钮单击事件。

该按钮是一个 TSpeedButton。

如有任何帮助,我们将不胜感激。 谢谢,

请阅读 Embarcadero 的文档。

FMX.Dialogs.MessageDlg

If a call to MessageDlg does not include the ACloseDialogProc parameter, the call is blocking on all platforms; that is, MessageDlg does not return until the dialog box closes. Android does not support these blocking calls, you can only use MessageDlg on Android if you provide the ACloseDialogProc parameter.

此功能已添加到 XE7 中:

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, . 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.

If you call InputBox, InputQuery, or MessageDlg and you do not provide an anonymous method on your call, these methods behave as they used to behave in XE6: calls are blocking on all platforms, including iOS, and Android is not supported.

例如:

MessageDlg('Do you wish to continue?', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], 0,
  procedure(const AResult: TModalResult)
  begin
    if AResult = mrYes then
      TakeImageClick(Self);
  end
);