The demo application below asks the user if they really want to close when they try to close the form.
This works fine when the form is not minimised. However, if they try to close the application from the Taskbar when the form is minimised, the app gets locked up and can only be closed from Task Manager.
It seems that the modal warning message is shown but not visible. Since they can't close the modal message box, they can't close it at all, even after restoring the window.
Note that a VCL application with similar code, using TApplication.MessageBox does not have an issue. The message box appears as soon as the X is clicked from the Taskbar and the app can be closed.
Note also that a similar FMX application made in Delphi 10 does not have the issue.
Does anyone have any ideas for a solution?
I've tried forcing the form's WindowState to wsNormal before showing the message box and calling Application.ProcessMessages, but it doesn't change anything.
I'm using a synchronous message box because this is to prevent loss of unsaved work in my application. I don't want the user to be able to close the application until they've clicked Yes in the message box.
DFM:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 347
ClientWidth = 437
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
OnClose = FormClose
DesignerMasterStyle = 0
end
Code:
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;
type
TForm1 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
uses
FMX.DialogService.Sync;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if TDialogServiceSync.MessageDialog(
'Are you sure you want to close?', TMsgDlgType.mtWarning,
[TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo],
TMsgDlgBtn.mbYes, 0) = mrNo then
Action := TCloseAction.caNone;
end;
end.