• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

Terminete application ?

I have multiple forms in my program and when i click on X in some form it only hides form but is dosen't terminate application. So how can i terminate application when someone click on X.
0
65zgtre45rr
Asked:
65zgtre45rr
  • 5
  • 2
  • 2
  • +3
2 Solutions
 
Russell LibbySoftware Engineer, Advisory Commented:
That is because the app will only terminate on the closing of the main form. For the other forms, you can add the following code to the Form's OnClose event handler:

eg:

procedure TFormX.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   Application.Terminate;
end;

Regards,
Russell

0
 
65zgtre45rrAuthor Commented:
I done this but is not working all forms are hidden but my apllication is still running :(
0
 
65zgtre45rrAuthor Commented:
I have put msg box in OnClose evenet to see if this gets executed and it is executed but application is not terminated. Only forms are hiden.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RickJCommented:
Put

Action := caFree ;

in the onclose event.
0
 
65zgtre45rrAuthor Commented:
Didn't help :(
0
 
RickJCommented:
How is your application structured??
Is it an MDI app or are you just creating "normal" forms?
0
 
65zgtre45rrAuthor Commented:
normal forms
0
 
2266180Commented:
I figure you have some thread running? or an infinite loop in on of the forms with an aplicaiton.processmessages? or some other way of passing the control from the loop to the main thread.
if so, you need to write a little code to either break the loop, or to kill the thread.
0
 
saravananvgCommented:
Hello Sir,

  If it is modal form, then Self.Close should close it, otherwise Action := caFree ; on close event should do.

with regards,
padmaja.
0
 
65zgtre45rrAuthor Commented:
I have indy IdHttp which i think creates in new thread.
0
 
2266180Commented:
you will have to kill the indy thread then. you have 2 options:
- force a disconnect on the indy component and wait a few seconds for the disconnect to kick in. do this BEFORE closing the form. (this is the recommended way)
- search and kill all threads (dunno how easy this would be)
0
 
rafaelfrancoCommented:
You may try Halt() that causes a abnormal application end.

procedure TFormX.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   Halt();
end;

be sure to free all objects and close all datasets before using this command.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 5
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now