码迷,mamicode.com
首页 > 其他好文 > 详细

Delphi用TActionList下载文件

时间:2014-06-11 08:19:08      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:class   blog   code   http   tar   ext   

TActionList有个标准动作TDownLoadURL,内部是使用的URLDownloadToFile,它下载文件时会定时产生OnDownloadProgress 事件,这样就可以用进度条显示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
     FileName := ‘logo.jpg‘;
     OnDownloadProgress := URL_OnDownloadProgress;
     ExecuteTarget(nil) ;
   finally
     Free;
   end;
   showMessage(‘OK‘);
   ProgressBar1.Max := 0;
end;

  

Delphi用TActionList下载文件,布布扣,bubuko.com

Delphi用TActionList下载文件

标签:class   blog   code   http   tar   ext   

原文地址:http://www.cnblogs.com/evil39c/p/3773324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!