Search code examples
delphiwindows-10firemonkey

TDialogService.ShowMessage not blocking on Win10


In my Delphi 10.4 FMX program, I am asking the user for a new file name using the code below

procedure TForm6.btnBlockingClick(Sender: TObject);
begin
  //In Win10, this blocks form access when ShowMessage is called
  NameCallBack(mrOk, ['name']);
end;

procedure TForm6.btnNonBlockingClick(Sender: TObject);
begin
  //In Win10, this does not block form access when ShowMessage is called in the NameCallBack routine.
  TDialogService.InputQuery('Enter name', ['Name'], [''], NameCallBack);
end;

procedure TForm6.NameCallBack(const AResult: TModalResult; const AValues:  array of string);
begin
  if aResult = mrOK then
    TDialogService.ShowMessage('Ok pressed')
  else
    TDialogService.ShowMessage('Cancel pressed');
end;

Any idea why ShowMessage is not blocking when NameCallBack is used as the Callback event for InputQuery? In Win10, what is the best way to show a message to a user in this type of callback routine that keeps the user from accessing the underlying form until the dialog is closed in some way.

FYI: the same thing happens if you use MessageDialog, to allow user interaction, instead of ShowMessage in the callback routine.

Note: this logic works in OSX and IOS, with both dialogs blocking. On Android, neither dialog is blocking but is not a problem, as touching anywhere but the dialogs closes the dialog and requires a second touch to interact with the underlying form again. On Win10, I can doing anything I want with the underlying form while the ShowMessage dialog is visible when used in a callback event.

Thanks for any help with this.


Solution

  • This may not be the best way to work around the bug I found, but here is what I did in case someone else has this problem.

    I added a timer to my form, set the interval to 200 and disabled it.

    For any TDialogServices.MessageDialog and TDialogServices.InputQuery callback routine where the callback routine also called MessageDialog or ShowMessage, I moved the callback logic into new routines. I then changed the callback routines to set a form variable to indicate which callback routine was called, saved off the relevant info from the callback routine as needed, then enabled the timer.

    In the timer event, I first disable the timer then call the new routines based on the form variable.

    This now allows both the original dialog and the dialog needed in the callback routine to be blocking on Win10. In addition, Android, OSX and IOS appear to still work correctly as explained in my question.