Solved

Terminating an application immediately...???

Posted on 2001-08-31
18
315 Views
Last Modified: 2010-04-06
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
Comment
Question by:naufal
18 Comments
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
Application.Terminate;
0
 
LVL 21

Expert Comment

by:ziolko
Comment Utility
damn!! too late
ziolko.
0
 
LVL 2

Expert Comment

by:RickHalle
Comment Utility
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
 

Author Comment

by:naufal
Comment Utility
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
 
LVL 2

Expert Comment

by:RickHalle
Comment Utility
Thats what I thought. What are you using to download?

Rick Halle
0
 

Author Comment

by:naufal
Comment Utility
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
 

Author Comment

by:naufal
Comment Utility
i m using a component called THttpCli for downloading.
0
 
LVL 2

Expert Comment

by:RickHalle
Comment Utility
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
 
LVL 1

Expert Comment

by:Kristian
Comment Utility
i find halt works best...
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Expert Comment

by:Dennis9
Comment Utility
Hi.
What if u also have ProcessMessages i it?

  Application.ProcessMessages;
  Application.Terminate;

Dennis
0
 

Author Comment

by:naufal
Comment Utility
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
 

Expert Comment

by:Jasbev
Comment Utility
You could use the application.destroy procedure. This will probably work...
0
 
LVL 2

Expert Comment

by:RickHalle
Comment Utility
Is the download aborting?
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
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
 

Author Comment

by:naufal
Comment Utility
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
 
LVL 2

Expert Comment

by:RickHalle
Comment Utility
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
 

Author Comment

by:naufal
Comment Utility
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
 
LVL 2

Accepted Solution

by:
RickHalle earned 25 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now