App stop help

I have two forms in my project, when I clicked the show form 2 button in form1, form2 will appear, I want to end my entire application by clicking the close button on form2,

Can anyone tell me how can I do this?

+3
source share
4 answers

If you mean when you click TButton named Close, then in the event of the Button.OnClick event Application.Terminate;

If you mean when the form X button is pressed, then in the Form2 OnClose event, call Application.Terminate;

+4
source

Application.Terminate, , OnCloseQuery OnClose (, , ).

Application.MainForm.Close;

( ).

+16

Another option is to send a wm_Close message to application / application.mainform

PostMessage(Application.Handle,wm_Close,0,0);

or

PostMessage(Application.MainForm.Handle,wm_Close,0,0);

This puts the close request in the message queue, existing messages already in the message queue will continue to be processed in the first place.

0
source

The simplest message mode for the user is TerminateProcess (GetCurrentProcessID, 0); no ask, no freeze, no s * iet.

-4
source

Source: https://habr.com/ru/post/1725940/