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...
naufalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

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.