Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Download a file from the Internet with progress indicator

By Zarko Gajic, About.com

If you need to save the contents of a specified URL to a file - and be able to track the download progress, use the TDownLoadURL Delphi action
While TDownLoadURL is writing to the specified file, it periodically generates an OnDownloadProgress event, so that you can provide users with feedback about the process.

Here's an example - note that you must include the unit ExtActns in the uses clause.

~~~~~~~~~~~~~~~~~~~~~~~~~
uses ExtActns, ...

type
   TfrMain = class(TForm)
   ...
   private
     procedure URL_OnDownloadProgress
        (Sender: TDownLoadURL;
         Progress, ProgressMax: Cardinal;
         StatusCode: TURLDownloadStatus;
         StatusText: String; var Cancel: Boolean) ;
   ...

implementation
...

procedure TfrMain.URL_OnDownloadProgress;
begin
   ProgressBar1.Max:= ProgressMax;
   ProgressBar1.Position:= Progress;
end;

function DoDownload;
begin
   with TDownloadURL.Create(self) do
   try
     URL:='http://z.about.com/6/g/delphi/b/index.xml';
     FileName := 'c:\ADPHealines.xml';
     OnDownloadProgress := URL_OnDownloadProgress;

     ExecuteTarget(nil) ;
   finally
     Free;
   end;
end;

{
Note:
URL property points to Internet
FileName is the local file
}
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Positioning the caret in a line in a Memo or RichEdit
« How to determine the output of a console application

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2003 Delphi Tips
  7. Download a file from the Internet with progress indicator

©2009 About.com, a part of The New York Times Company.

All rights reserved.