源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Delphi用TActionList实现下载文件的方法

  • 时间:2021-07-02 02:08 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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.1sucai.cn/images/logo.gif';
   FileName := 'logo.gif';
   OnDownloadProgress := URL_OnDownloadProgress;
   ExecuteTarget(nil) ;
  finally
   Free;
  end;
  showMessage('OK');
  ProgressBar1.Max := 0;
end;
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部