Delphi用TActionList实现下载文件的方法
Delphi中的TActionList有个标准动作TDownLoadURL,内部是使用的URLDownloadToFile,它下载文件时会定时产生OnDownloadProgress事件,这样就可以用进度条显示。
本文讲述了Delphi用TActionList实现下载文件的方法,实现代码如下所示:
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,ExtActns,ActnList,StdCtrls,ComCtrls;
type
TForm1=class(TForm)
Button1:TButton;
ActionList1:TActionList;
ProgressBar1:TProgressBar;
procedureButton1Click(Sender:TObject);
private
{Privatedeclarations}
procedureURL_OnDownloadProgress
(Sender:TDownLoadURL;
Progress,ProgressMax:Cardinal;
StatusCode:TURLDownloadStatus;
StatusText:String;varCancel:Boolean);
public
{Publicdeclarations}
end;
var
Form1:TForm1;
implementation
{$R*.dfm}
procedureTform1.URL_OnDownloadProgress;
begin
ProgressBar1.Max:=ProgressMax;
ProgressBar1.Position:=Progress;
end;
procedureTForm1.Button1Click(Sender:TObject);
begin
withTDownloadURL.Create(self)do
try
URL:='https://www.nhooo.com/images/logo.gif';
FileName:='logo.gif';
OnDownloadProgress:=URL_OnDownloadProgress;
ExecuteTarget(nil);
finally
Free;
end;
showMessage('OK');
ProgressBar1.Max:=0;
end;
热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短