Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Mar : IdHTTP simple downloader (structure questions)

www.cryer.info
Managed Newsgroup Archive

IdHTTP simple downloader (structure questions)

Subject:IdHTTP simple downloader (structure questions)
Posted by:"Bryan" (bryanray..@hotmail.com)
Date:21 Mar 2006 06:07:20

Hello group.
I'm trying to build a simple downloader program that will read an ini file to get its download tasks (url, download interval, filename to save as and post processing.....) based on a timer interval.

Using D7 and Indy 10.1.5.

I would like to create an instance of IdHTTP for every task when it is needed (based upon the interval in the ini file).

Here are some questions I'm having...

1. How do I know if the download was a success?
   (I know there is an OnStatus and OnWorkEnd info, but how do I add it to the procedure when I'm creating the instance dynamically)?
2. If it was not a success, how do I find out the error?
3. Will there be any problems with this setup if several instances are created and started at the same time... (does this need to be multithreaded or does Indy automatically handle this)?

Sample source code? (If someone has already done this type of thing)

Sorry for all of these newby type questions... I'm new to Delphi and Indy.


Here is the start of the main downloading code...
Procedure DownloadFile(InTask : TDownloadTask);
var
http : TIdHTTP;
DownloadedFile: TFileStream;
begin
  http := TIdHTTP.Create(Nil);
  Try
    http.Request.Clear;
    http.ProxyParams.Clear;
    http.Response.Clear;
    DownloadedFile :=
           TFileStream.Create(InTask.SaveAsFileName, fmCreate);
    HTTP.Get(InTask.URL, DownloadedFile);
    HTTP.Disconnect;
    HTTP.Free;
    DownloadedFile.Free;
  Except
    DownloadedFile.Free;
    HTTP.Free;
  end;
end;

Many thanks for any help you can provide.  :)
Best Regards,
Bryan

Replies:

www.cryer.info
Managed Newsgroup Archive