zoukankan      html  css  js  c++  java
  • Delphi用TActionList下载文件

    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;
    

      

  • 相关阅读:
    jsTree展开根节点 设置用户图标
    Js图片缩放代码 鼠标滚轮放大缩小 图片向右旋转
    MySQL删除重复数据
    200道物理学难题——001 三只蜗牛
    慎用GetOpenFileName
    Windows7隐藏字体
    Windows 位图
    Windows 调色板
    C++模板特化
    使用Visual Studio制作安装包
  • 原文地址:https://www.cnblogs.com/evil39c/p/3773324.html
Copyright © 2011-2022 走看看