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

Terminating an application immediately...???

How do i terminate an application immediately when the
"close" button is pressed even if the application is performing some action especially if it is downloading some file? that would mean aborting the download first...
0
naufal
Asked:
naufal
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
Application.Terminate;
0
 
ziolkoCommented:
damn!! too late
ziolko.
0
 
RickHalleCommented:
The best way to do this is have it cleanly terminate the download first. Windows tends to throw fits otherwise. It also depends on what you are using to download as to how you would go about this. I use a series of WinInet api calls that blockread the data while downloading. Prior to getting each block I do an application.processmessages. Then I check a variable called bAbort to see if it is set to true. If so I break out of the blockread, close the connection, etc. As you may have guessed bAbort is set to true if the user clicks the Abort button.

Rick Halle
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
naufalAuthor Commented:
no Application.Terminate doesn't close the App immediately. it waits till the download is complete. some other function is required that will force the termination.
0
 
RickHalleCommented:
Thats what I thought. What are you using to download?

Rick Halle
0
 
naufalAuthor Commented:
no Application.Terminate doesn't close the App immediately. it waits till the download is complete. some other function is required that will force the termination.
0
 
naufalAuthor Commented:
i m using a component called THttpCli for downloading.
0
 
RickHalleCommented:
Try putting this into the click event for the button and the CloseQuery fo the form:
  HttpCli1.Abort;

Your using the ICS Package correct?

Rick Halle
0
 
KristianCommented:
i find halt works best...
0
 
Dennis9Commented:
Hi.
What if u also have ProcessMessages i it?

  Application.ProcessMessages;
  Application.Terminate;

Dennis
0
 
naufalAuthor Commented:
how do i use the halt procedure?
i wrote:


Application.OnMessage := CloseMsg;

procedure TMainClass.CloseMsg(var Msg: TMsg; var Handled: Boolean);
begin
  if Msg.message = WM_CLOSE then
  begin
    HttpCli1.Abort;
    Halt;          // <---- control never reaches here
  end;
end;

nothing happened. i tried to debug but the control never reached the line of code that calls the Halt procedure.
0
 
JasbevCommented:
You could use the application.destroy procedure. This will probably work...
0
 
RickHalleCommented:
Is the download aborting?
0
 
rwilson032697Commented:
As Kristian says, halt works well. If you just want to stop the application in its tracks and shut it down nastily this is the way to do it.

Cheers,

Raymond.
0
 
naufalAuthor Commented:
NO RickHAlle, i never get to go past the if condition. the control doesn't reach the HttpCli1.Abort statement either. i wonder if it means (Msg.message = WM_CLOSE) is never true. but that isn't possible cos the app does close after a while, when the download is complete.

do i need to use some function other than OnMessage?
0
 
RickHalleCommented:
I don't know. I tested it using the onclick event for a button and the closequery event for the form.

EX.:
begin
  HttpCli1.Abort;
  Close;
end;
0
 
naufalAuthor Commented:
my problem doesn't allow me to use code on the events of the form or it's close button. i have to catch the event that the form should b closed and then do likewise.
0
 
RickHalleCommented:
If you never get to the HttpCli1.Abort; as shown in your code above then the WM_CLOSE message is never coming accross. Or I should say it does not coming accross as long as the download is happening. Have you tried using the httpcli in asynchronous mode instead of synchronous. That might allow your app to process messages. I suspect that the httpcli is wrapping up the messages and never allowing them to get there.

Rick Halle
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now