Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Mar : Re: IdHTTP simple downloader (structure questions)
| Subject: | Re: IdHTTP simple downloader (structure questions) |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Tue, 21 Mar 2006 11:28:36 |
"Bryan" <bryanray67@hotmail.com> wrote in message
news:44200898$1@newsgroups.borland.com...
> How do I know if the download was a success?
Just like with every other function and method in Indy, if no exception is
thrown then it succeeded.
> 2. If it was not a success, how do I find out the error?
That depends on the particular type of exception that is thrown, whether it
is a socket exception, or an HTTP exception, or a VCL exception, etc.
> Will there be any problems with this setup if several instances
> are created and started at the same time...
In order to do that, you will have to run each instance in its own thread.
> http.Request.Clear;
> http.ProxyParams.Clear;
> http.Response.Clear;
You do not need any of these. A new instance is created with everything
initially cleared.
> Try
> DownloadedFile :=
> TFileStream.Create(InTask.SaveAsFileName, fmCreate);
> HTTP.Get(InTask.URL, DownloadedFile);
> HTTP.Disconnect;
> HTTP.Free;
> DownloadedFile.Free;
> Except
> DownloadedFile.Free;
> HTTP.Free;
> end;
> end;
Rather than calling Free() in multiple places, use try..finally blocks
instead:
procedure DownloadFile(InTask : TDownloadTask);
var
http : TIdHTTP;
DownloadedFile: TFileStream;
begin
try
http := TIdHTTP.Create(nil);
try
DownloadedFile := TFileStream.Create(InTask.SaveAsFileName,
fmCreate);
try
http.Get(InTask.URL, DownloadedFile);
finally
DownloadedFile.Free;
end;
finally
http.Free;
end;
except
// failure, do something ...
end;
end;
Gambit
none