Embarcadero has created a new non blocking MessageDlg() function in Delphi XE7 and Appmethod Firemonkey to better support Android. The code does work on IOS, Windows, and OSX too. The new function takes an anonymous method as the last parameter and it gets executed when the user clicks one of the buttons. In Delphi XE5 and XE6 the function would block and would not execute code after the user clicked one of the buttons from the MessageDlg(). Here is the example MessageDlg() code from XE5 and XE6:
case MessageDlg('Do you want to press yes or no?', System.UITypes.TMsgDlgType.mtInformation,
[
System.UITypes.TMsgDlgBtn.mbYes, System.UITypes.TMsgDlgBtn.mbNo
], 0) of
{ Detect which button was pushed and show a different message }
mrYes:
begin
// pressed yes
end;
mrNo:
begin
// pressed no
Exit;
end;
end;
// code here would run after the button clicks
And here is the new code for Firemonkey XE7 with the anonymous method used:
MessageDlg('Do you want to press yes or no?', System.UITypes.TMsgDlgType.mtInformation,
[
System.UITypes.TMsgDlgBtn.mbYes, System.UITypes.TMsgDlgBtn.mbNo
], 0,
procedure(const AResult: TModalResult)
begin
case AResult of
{ Detect which button was pushed and show a different message }
mrYes:
begin
// pressed yes
end;
mrNo:
begin
// pressed no
end;
end;
end
);
// code here would get executed right away
Head over and check out the full documentation about the MessageDlg() function on the Embarcadero docwiki.
Here is a working example … http://severinfo.com/index.php/firemonkey/6-showmodal-v-firemonkey-prilozheniyakh-dlya-android
The question is: how do you programmatically close the dialog box in android (for example after showing an info box for 5 s)?
Use a Toast. Or just a TForm.
Project to compile in Delphi 10 seattle, presents this error:
[dcc32 Error] ufrmMain.pas(352): E2250 There is no overloaded version of ‘MessageDlg’ that can be called with these arguments
How to solve this error?
In Delphi Berlin it is now MessageDialogAsync and MessageDialogSync.