user1512695
user1512695

Reputation: 79

Incompatible types: 'TDownloadProgressEvent' and 'Procedure'

I am trying to download a file while having the status shown in a progress bar.

I followed the instructions located here: http://delphi.about.com/cs/adptips2003/a/bltip0903_2.htm

Here is my code:

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.

Upon compiling i get the following error:

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

It is referring to this line of code:

OnDownloadProgress := TForm5.URL_OnDownloadProgress;

I am having trouble fixing this error.. Any help would be greatly appreciated.

Thanks.

Upvotes: 1

Views: 803

Answers (2)

RRUZ
RRUZ

Reputation: 136391

TForm5.URL_OnDownloadProgress is not a valid sentence, you must use the instance of the form (not the tyoe) instead, so try writting something like so

 OnDownloadProgress := Self.URL_OnDownloadProgress;

or

 OnDownloadProgress := URL_OnDownloadProgress;

Upvotes: 5

mjn
mjn

Reputation: 36634

Remove TForm5:

OnDownloadProgress := URL_OnDownloadProgress

Upvotes: 2

Related Questions