Solved

Terminating an application immediately...???

Posted on 2001-08-31
18
320 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: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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 25 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…

832 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