How to close TDialogService.MessageDialog() automatically after a certain time in Delphi FMX on Android?

huangapple go评论157阅读模式
英文:

How to close TDialogService.MessageDialog() automatically after a certain time in Delphi FMX on Android?

问题

我在Delphi FMX上的Android平台上有以下代码:

```delphi
TDialogService.MessageDialog('测试关闭消息', TMsgDlgType.mtInformation,
                  [TMsgDlgBtn.mbOK], TMsgDlgBtn.mbOK, 0, nil);

我需要在3秒后自动关闭TDialogService.MessageDialog

我尝试了Screen.MousePos.SetLocation(x, x)来模拟点击。


<details>
<summary>英文:</summary>

I have the following code in Delphi FMX on Android:

```delphi
TDialogService.MessageDialog(&#39;Test Close message&#39;, TMsgDlgType.mtInformation,
                  [TMsgDlgBtn.mbOK], TMsgDlgBtn.mbOK, 0, nil);

I need to auto-close TDialogService.MessageDialog after 3 seconds.

I tried Screen.MousePos.SetLocation(x, x) for set a tap to simulate.

答案1

得分: 2

在Android上,TDialogService.MessageDialog() 简单地调用 IFMXDialogServiceAsync.MessageDialogAsync()(因为Android不支持同步对话框)。 默认实现位于 FMX.Dialogs.Android 单元中的 TFMXDialogService 类中。

您无法访问它创建的UI对话框,因此无法手动关闭它。 但是,您可以编写自己的类,实现 IFMXDialogServiceAsync 接口,然后 将该类注册到FMX(您需要首先 删除默认服务)。 然后,您可以对您的对话框实现执行任何操作。 例如,您可以显示自己的带有计时器的窗体以关闭窗体。

英文:

On Android, TDialogService.MessageDialog() simply calls IFMXDialogServiceAsync.MessageDialogAsync() (as Android does not support synchronous dialogs). The default implementation is buried in the TFMXDialogService class in the FMX.Dialogs.Android unit.

You don't have access to the UI dialog it creates, so you can't close it manually. But, what you could do is write your own class that implements the IFMXDialogServiceAsync interface, and then register that class with FMX (you will have to remove the default service first). Then, you can do whatever you want with your dialog implementation. For instance, you could display your own Form that has a timer on it to close the Form.

huangapple
  • 本文由 发表于 2023年8月11日 03:37:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76878835.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定