Skip to content Skip to sidebar Skip to footer

Modal Android Dialog Using Delphi 10.2.1 Tokyo

I have the following Delphi code for showing a modal message on Android which worked fine on 10.1 Berlin, but stopped working on Delphi 10.2.1 Tokyo. This procedure now hangs the A

Solution 1:

On Android we have only asynchronous dialog boxes. If we want they act as modal dialog box, we have to do ourself.

The solution with a ProcessMessage loop is an idea, but I don't think it's the best approach.

An other one is to add a transparent (or opaque) layout (or rectangle) on your form before displaying the dialog box and when you have an answer, you can remove the blockin layout.

You can also use TFrameStand from Andrea Magni (downloadable directly from GetIt) who propose to use a TFrame as a dialog box. https://github.com/andrea-magni/TFrameStand

Solution 2:

I have restructured a lot of code to use asynchronous callbacks, but where callback hell ensues (especially on large existing projects), I have found the following works:

Instead of just using Application.ProcessMessages, I am now calling CheckSynchronize as well.

procedure TfrmStock.WaitForModalWindowToClose;
beginwhile FModalWindowOpen dobegin
       Sleep(40);
       Application.ProcessMessages;
       CheckSynchronize;
    end;
end;

Solution 3:

I think the following code should work:

function ShowMessageOKCancel(AMessage: String): String;
var
  lResultStr: String;
begin
  lResultStr:='';
  TDialogService.PreferredMode:=TDialogService.TPreferredMode.Platform;
  TDialogService.MessageDialog(AMessage, TMsgDlgType.mtConfirmation,
    FMX.Dialogs.mbOKCancel, TMsgDlgBtn.mbOK, 0,
    procedure(const AResult: TModalResult)
    begin
      case AResult of
        mrOK: lResultStr:='O';
        mrCancel:  lResultStr:='C';
      end;
    end);

  Result:=lResultStr;
end;

When you call this function, it should show a dialog with your message and the two buttons OK and Cancel. The return value will indicate which button was clicked.

Post a Comment for "Modal Android Dialog Using Delphi 10.2.1 Tokyo"