Download a file from the Internet with progress indicator

Submitted by:Jhon Brain

Date added:04 August, 2012

Category:Delphi

Note that you must include the unit ExtActns in the uses clause.

Tags: download progress , progress indicator

Code Snippet:

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://0.tqn.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
}
 
 

Comments