Delphi用TActionList完成下載文件的辦法。本站提示廣大學習愛好者:(Delphi用TActionList完成下載文件的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是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; procedure Button1Click(Sender: TObject); private { Private declarations } procedure URL_OnDownloadProgress (Sender: TDownLoadURL; Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String; var Cancel: Boolean) ; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure Tform1.URL_OnDownloadProgress; begin ProgressBar1.Max:= ProgressMax; ProgressBar1.Position:= Progress; end; procedure TForm1.Button1Click(Sender: TObject); begin with TDownloadURL.Create(self) do try URL:='http://www.jb51.net/images/logo.gif'; FileName := 'logo.gif'; OnDownloadProgress := URL_OnDownloadProgress; ExecuteTarget(nil) ; finally Free; end; showMessage('OK'); ProgressBar1.Max := 0; end;