?
Solved

Terminating an application immediately...???

Posted on 2001-08-31
18
Medium Priority
?
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
18 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6444334
Application.Terminate;
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6444352
damn!! too late
ziolko.
0
 
LVL 2

Expert Comment

by:RickHalle
ID: 6444404
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
Independent Software Vendors: 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!

 

Author Comment

by:naufal
ID: 6444432
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
ID: 6444451
Thats what I thought. What are you using to download?

Rick Halle
0
 

Author Comment

by:naufal
ID: 6444459
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
ID: 6444485
i m using a component called THttpCli for downloading.
0
 
LVL 2

Expert Comment

by:RickHalle
ID: 6444515
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
ID: 6444687
i find halt works best...
0
 
LVL 1

Expert Comment

by:Dennis9
ID: 6445702
Hi.
What if u also have ProcessMessages i it?

  Application.ProcessMessages;
  Application.Terminate;

Dennis
0
 

Author Comment

by:naufal
ID: 6447351
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
ID: 6447573
You could use the application.destroy procedure. This will probably work...
0
 
LVL 2

Expert Comment

by:RickHalle
ID: 6447718
Is the download aborting?
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 6449489
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
ID: 6449808
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
ID: 6449898
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
ID: 6450333
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 100 total points
ID: 6450379
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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