Delphi fmx 阻止消息对话框

Delphi fmx blocked message Dialog box

在使用 android 使用 java 或 android studio 开发的应用程序时,我发现消息对话框提示会一直执行下一行,直到对话框提示得到回答。我一直在尝试使用 TDialogService.MessageDialog(AMessage, ADialogType, AButtons, ADefaultButton, 0, procedurexyz) 来做到这一点。当显示提示时,将执行下一行,使提示无用,因为用户本应决定下一步操作。我需要任何人的帮助才能获得活动块消息对话框提示。

Embarcadero documentation says,在 Android 平台上,您只能对 ShowMessageMessageDialogmyForm.ShowModal 等使用非阻塞调用

要获得 "blocking" 模式,您可以使用变通方法,如下所示:

function myMessageDialog(const AMessage: string; const ADialogType: TMsgDlgType;
  const AButtons: TMsgDlgButtons; const ADefaultButton: TMsgDlgBtn): Integer;
var
  mr: TModalResult;
begin
  mr:=mrNone;
  // standart call with callback anonimous method
  TDialogService.MessageDialog(AMessage, ADialogType, AButtons,
    ADefaultButton, 0,
    procedure (const AResult: TModalResult) 
    begin 
      mr:=AResult 
    end);

  while mr = mrNone do // wait for modal result
    Application.ProcessMessages;
  Result:=mr;
end;

在你的建议@Kami 之后,我想到了这个并且它对我来说非常有效,尽管我愿意接受建议或补充。


function MsgBox(const AMessage: string; const ADialogType: TMsgDlgType; const AButtons: TMsgDlgButtons;
    const ADefaultButton: TMsgDlgBtn ): Integer;
var
    myAns: Integer;
    IsDisplayed: Boolean;
begin
    myAns := -1;
    IsDisplayed := False;</p>

<pre><code>While myAns = -1 do
Begin
    if IsDisplayed = False then
    TDialogService.MessageDialog(AMessage, ADialogType, AButtons, ADefaultButton, 0,
            procedure (const AResult: TModalResult)
            begin
                myAns := AResult;
                IsDisplayed := True;
            end);

    IsDisplayed := True;
    Application.ProcessMessages;
End;

Result := myAns;

end;