In VCL, closing the main form of the program also means that the main loop of the program ends and the main program ends naturally. So you can use the closing function (close) of the form in the main form, as follows:
Procedure Tfrmmain.btncloseclick (Sender:tobject);
Begin
Close;
End
In FMX, the concept of form is replaced by activity, although the Tform class still exists, but MainForm cannot end the program by closing the function, using application.terminate is not valid, and is adjusted to:
Uses
FMX. platform.android;
Procedure Tform2.speedbutton1click (Sender:tobject);
Begin
Mainactivity.finish;
End
At this time the program is closed directly, if you need to ask before exiting, you can refer to the approach in VCL, in the button event still use the close function, in the Onclosequery event to ask whether to exit, in the OnClose event to implement the program's shutdown, as follows:
Uses
FMX. platform.android;
Procedure Tfrmmain.formclose (Sender:tobject; var action:tcloseaction);
Begin
{Exit Program}
Mainactivity.finish;
End
Procedure Tfrmmain.formclosequery (Sender:tobject; var canclose:boolean);
Begin
If Messagedlg (' Do you want to quit? ‘,
Tmsgdlgtype.mtconfirmation,
[Tmsgdlgbtn.mbok, Tmsgdlgbtn.mbcancel],
-1) = Mrok Then
Canclose: = True
Else
Canclose: = false;
End
Procedure Tfrmmain.btncloseclick (Sender:tobject);
Begin
Close;
End
Run the following in the virtual machine:
Reference: http://www.cnblogs.com/key-ok/p/3357573.html
Http://www.cnblogs.com/key-ok/p/3357576.html
Application Close exit (in FMX, activity replaces the concept of form)