2012-07-09 88 views
1

我试图在进度条中显示状态的同时下载文件。不兼容的类型:'TDownloadProgressEvent'和'Procedure'

我跟着位于这里的指示: 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; 

我在修复此错误时遇到问题.. 任何帮助将不胜感激。

谢谢。

回答

5

TForm5.URL_OnDownloadProgress不是有效的句子,你必须使用的形式(而不是tyoe)的实例,而不是,所以尽量书面方式像这样

OnDownloadProgress := Self.URL_OnDownloadProgress; 

OnDownloadProgress := URL_OnDownloadProgress; 
+0

谢谢,我用OnDownloadProgress:= URL_OnDownloadProgress; – user1512695 2012-07-09 17:54:31

2

删除TForm5:

OnDownloadProgress := URL_OnDownloadProgress