1

プログレスバーにステータスが表示されている状態でファイルをダウンロードしようとしています。

私はここにある指示に従いました: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;

このエラーの修正に問題があります。ご協力いただければ幸いです。

ありがとう。

4

2 に答える 2

5

TForm5.URL_OnDownloadProgressは有効な文ではありません。代わりにフォームのインスタンス(tyoeではなく)を使用する必要があるため、次のように記述してみてください。

 OnDownloadProgress := Self.URL_OnDownloadProgress;

また

 OnDownloadProgress := URL_OnDownloadProgress;
于 2012-07-09T17:40:06.137 に答える
2

TForm5を削除します。

OnDownloadProgress := URL_OnDownloadProgress
于 2012-07-09T17:39:51.623 に答える