Re: Aborting a Get?

Giganews Newsgroups
Subject: Re: Aborting a Get?
Posted by:  Thomas Bergerot (nospam@nospam.fr)
Date: Fri, 02 May 2008

mojoala a écrit :
> How do you abort an HTTP.Get?
>
> The Customer may want to Cancel a long download.
>
> What call do I make?
>
> TIA

[This procedure is from the Indy FAQ ofwww.developpez.com]

Since there is no Abort method, you can interrupt the transfer by
calling EndWork via the IOHandler object of TIdHttp.

You declare a bool property :

  TTestForm = class(TForm)
  private
    FRunning : Boolean;
  public
    { Public declarations }
  end;

At the begginning of the transfer, in the OnWorkBegin, we have :

procedure TTestForm.IdHTTPWorkBegin(ASender: TObject; AWorkMode: TWorkMode;
  AWorkCountMax: Integer);
begin
  if AWorkMode = wmRead then
  begin
    FRunning := True;
  end;
end;

Then, we drop a button for stopping the download :

procedure TTestForm.btnStopClick(Sender: TObject);
begin
  FRunning := not FRunning;
end;

And we'll then write OnWork :

procedure TTestForm.IdHTTPWork(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Integer);
begin
  Application.ProcessMessages;
  if not Frunning then
      IdHTTP.IOHandler.CloseGracefully;
end;

Replies

In response to

Aborting a Get? posted by mojoala on Thu, 1 May 2008