程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi用TActionList下載文件

Delphi用TActionList下載文件

編輯:Delphi

TActionList有個標准動作TDownLoadURL,內部是使用的URLDownloadToFile,它下載文件時會定時產生OnDownloadProgress 事件,這樣就可以用進度條顯示:

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://static.cnblogs.com/images/logo_small.gif';
     FileName := 'logo.jpg';
     OnDownloadProgress := URL_OnDownloadProgress;
     ExecuteTarget(nil) ;
   finally
     Free;
   end;
   showMessage('OK');
   ProgressBar1.Max := 0;
end;

  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved