Home > Back-end >  Delphi android formclosequery events
Delphi android formclosequery events

Time:11-11

Var Check: Boolean;
The begin
Check:=False;

MessageDlg (' confirm exit? 'System. UITypes. TMsgDlgType. MtInformation, [TMsgDlgBtn. MbYes, TMsgDlgBtn. MBN. MbCancel], 0,
Procedure (const AResult: TModalResult)
The begin
If AResult=mrYES thenCheck:=FalTrueeCancel ');

AnClose:=Check;
end;

The same code in Windows platform will be a problem, why in the android platform can't close the window? Feel just skip the MessageDlg, if the first line to Check:=True, and will close the window directly,,, where is wrong, how to write properly display a prompt dialog box and allows the button? Changed many times, or not to display a message box directly, or shows the point after yes or no, either all, or will close the window, the trouble the great god help to find out what is going on, thank you! End);
The results are directly related to the

CodePudding user response:

TDialogService. MessageDialog (' Choose a button: 'System. UITypes. TMsgDlgType. MtInformation,
[System. UITypes. TMsgDlgBtn. MbYes, System. UITypes. TMsgDlgBtn. MbNo, System. UITypes. TMsgDlgBtn. MbCancel],
System. UITypes. TMsgDlgBtn. MbYes, 0,

//Use an anonymous method to make sure the acknowledgment appears as expected.
Procedure (const AResult: TModalResult)
The begin
Case AResult of
{Detect which button was pushed and show a company's message}
MrYES:
//Check:=False;
//anClose:=Check;
ShowMessage (' You chose, Yes');


MrNo:
ShowMessage (' You chose, No ');
MrCancel:
ShowMessage (' You chose, Cancel ');
end;
End);


CodePudding user response:

reference 1st floor qq_457565758 response:
TDialogService. MessageDialog (' Choose a button: 'System. UITypes. TMsgDlgType. MtInformation,
[System. UITypes. TMsgDlgBtn. MbYes, System. UITypes. TMsgDlgBtn. MbNo, System. UITypes. TMsgDlgBtn. MbCancel],
System. UITypes. TMsgDlgBtn. MbYes, 0,

//Use an anonymous method to make sure the acknowledgment appears as expected.
Procedure (const AResult: TModalResult)
The begin
Case AResult of
{Detect which button was pushed and show a company's message}
MrYES:
//Check:=False;
//anClose:=Check;
ShowMessage (' You chose, Yes');


MrNo:
ShowMessage (' You chose, No ');
MrCancel:
ShowMessage (' You chose, Cancel ');
end;
End);
sorry to 1/f, somehow it off, some characters deleted incomplete, back upstairs, I used your code, he changed to:

TDialogService. MessageDialog (' confirm exit? '
System. UITypes. TMsgDlgType. MtInformation,
[System. UITypes. TMsgDlgBtn. MbYes, System. UITypes. TMsgDlgBtn. MbNo],
System. UITypes. TMsgDlgBtn. MbYes, 0,

//Use an anonymous method to make sure the acknowledgment appears as expected.
Procedure (const AResult: TModalResult)
The begin
Case AResult of
{Detect which button was pushed and show a company's message}
MrYES:
The begin
Check:=True;
ShowMessage (' You chose, Yes');
end;


MrNo:
ShowMessage (' You chose, No ');
end;
End);

If the Check=True then
The begin
ShowMessage (' You chose, Yes');
CanClose:=True;
end;

But the problem is coming, this code:

If the Check=True then
The begin
ShowMessage (' You chose, Yes');
CanClose:=True;
end;

Were carried out to determine whether the user in the previous message has chosen the True, but I found the runtime application will skip TDialogService. MessageDialog closed form directly, if the if Check=True and then delete the following code, and can display the message box and can be different according to button tips, but this can't CanClose closed form, don't know where the problem is, how should solve?

CodePudding user response:

Var
FCanClose: Boolean;
The begin
FCanClose:=false;
If not FCanClose then
FMX. Dialogs. MessageDlg (
'the Exit? '
TMsgDlgType mtConfirmation,
[TMsgDlgBtn mbYes, TMsgDlgBtn mbNo],
0,
Procedure (const AResult: TModalResult)
The begin
If AResult=mrYes then
The begin
FCanClose:=True;//set the field value
The Close;//call the close again
end;
End);

CanClose:=FCanClose;
end;

CodePudding user response:

Upstairs tried, the method of flash point yes message box will (close the pop up again and again after can't avoid no exit), the form is still unable to close, says Mr ZhuoPing online audience message box is asynchronous mode, namely a pop-up message range after the user clicks the button will continue to carry out, so I think if put MessageDlg CanClose:=FCanClose behind words might be just skip, so change to this:
Define a global variable var FCanClose: Boolean=False;

FormCloseQuery event code:

Procedure TMainForm. FormCloseQuery (Sender: TObject; Var CanClose: Boolean);
The begin
CanClose:=FCanClose;

MessageDlg (' confirm exit? '
System. UITypes. TMsgDlgType. MtInformation,
[System. UITypes. TMsgDlgBtn. MbYes, System. UITypes. TMsgDlgBtn. MbNo], 0,
Procedure (const AResult: TModalResult)
The begin
If AResult=mrYES then
The begin
FCanClose:=True;
The Self. The Close;
end;
End)
end;

After the problem solved (click yes will pop-up message again, but only for an instant, closed form)

CodePudding user response:

Platform Without ACloseDialogProc With ACloseDialogProc
Windows Blocking Blocking
OS X Blocking Blocking
IOS Blocking Non - Blocking
Android Non - blocking
  • Related