Application Close exit (in FMX, activity replaces the concept of form)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.