• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • 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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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