delphi - 不兼容的类型:“TDownloadProgressEvent”和“过程”

标签 delphi download progress-bar

我正在尝试在进度栏中显示状态的同时下载文件。

我按照此处的说明进行操作:
http://delphi.about.com/cs/adptips2003/a/bltip0903_2.htm

这是我的代码:

unit unitUpdate;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, StdCtrls, ComCtrls, ExtActns;

type
  TForm5 = class(TForm)
    ProgressBar1: TProgressBar;
    SaveDialog1: TSaveDialog;
  private
    procedure URL_OnDownloadProgress
        (Sender: TDownLoadURL;
         Progress, ProgressMax: Cardinal;
         StatusCode: TURLDownloadStatus;
         StatusText: String; var Cancel: Boolean) ;
         function DoDownload: boolean;
  public
    { Public declarations }
  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}

procedure TForm5.URL_OnDownloadProgress;
begin
   ProgressBar1.Max:= ProgressMax;
   ProgressBar1.Position:= Progress;
end;

function TForm5.DoDownload: Boolean;
begin
  ShowMessage('A new update is available!');
  savedialog1.Title := 'Save Update';
  savedialog1.Filter := 'Exe Files (*.exe)|*.exe';
  savedialog1.Execute;
  if savedialog1.filename = '' then
    Application.Terminate
  else begin
   with TDownloadURL.Create(self) do
   try
     URL:='linktofile';
     FileName := savedialog1.FileName + '.exe';
     OnDownloadProgress := TForm5.URL_OnDownloadProgress;

     ExecuteTarget(nil) ;
   finally
     Free;
   end;
  end;
end;

end.


编译后出现以下错误:

[DCC Error] unitUpdate.pas(50): E2010 Incompatible types: 'TDownloadProgressEvent' and 'Procedure'


它指的是这一行代码:

OnDownloadProgress := TForm5.URL_OnDownloadProgress;


我无法解决此错误。
任何帮助将不胜感激。

谢谢。

最佳答案

TForm5.URL_OnDownloadProgress不是有效的句子,必须改用形式的实例(而不是tyoe),因此请尝试编写如下形式

 OnDownloadProgress := Self.URL_OnDownloadProgress;


要么

 OnDownloadProgress := URL_OnDownloadProgress;

关于delphi - 不兼容的类型:“TDownloadProgressEvent”和“过程”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11400182/

相关文章:

delphi - 根据字符串中的第一个数字递增

swift - Label 和 ProgressBar 不会更新 macOS Swift

python - 在 CLI 应用程序中创建进度条

Windows 10 上的 Delphi 2007 - 下载 Borland.xxx.Targets 文件

delphi - 如何对24位位图使用ScanLine属性?

delphi - 从 cxLookAndFeelPaintersmanager 中删除皮肤

c# - 下载文件时如何限制带宽并允许多次下载?

java - 在一些 URL 上获取 FileNotFoundException。正在尝试下载

php - Apache 和 PHP 的选择性文件下载权限

javascript - 使用 jquery ajax 和 FormData 跟踪文件上传的 ajax 发布进度