noob
noob

Reputation: 203

application terminate help

in my project i have two forms ,when i clicked show form 2 button in form1 ,form2 will pop up ,i want to terminate my whole application by clicking close button on form2 ,

can anyone please tell me how can i do this ?

Upvotes: 4

Views: 8826

Answers (4)

skamradt
skamradt

Reputation: 15548

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

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

or

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

This places the close request in the message queue, existing messages already in the message queue will continue to process first.

Upvotes: 0

delphigeist
delphigeist

Reputation: 73

The post easiest mode is to user TerminateProcess(GetCurrentProcessID, 0); no ask, no freeze, no s*iet.

Upvotes: -5

mghie
mghie

Reputation: 32344

Do not use Application.Terminate if you want your OnCloseQuery and OnClose handlers of the main app form to be called (for example to be able to cancel this or to ask whether to save modified files or such).

You can call

Application.MainForm.Close;

instead, from all forms (even the main form itself).

Upvotes: 17

J__
J__

Reputation: 3837

If you mean when a TButton called Close is clicked, then in the Button.OnClick event call Application.Terminate;

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

Upvotes: 5

Related Questions