当前位置: 首页 > 新闻动态 > 软件编程

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

作者:用户投稿 浏览: 发布日期:2026-01-16
[导读]:这篇文章主要介绍了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:='https://www./images/logo.gif';
   FileName := 'logo.gif';
   OnDownloadProgress := URL_OnDownloadProgress;
   ExecuteTarget(nil) ;
  finally
   Free;
  end;
  showMessage('OK');
  ProgressBar1.Max := 0;
end;
免责声明:转载请注明出处:http://m.jing-feng.com.cn/news/342011.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!