Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Problem mit TDownloadURL (https://www.delphipraxis.net/171394-problem-mit-tdownloadurl.html)

iphi 5. Nov 2012 12:37

Delphi-Version: 6

Problem mit TDownloadURL
 
Hallo,

ich versuche mit meinem Code eine Datei aus dem Internet herunterzuladen:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,ExtActns, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    ProgressBar1: TProgressBar;
    Button1: TButton;
    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);
const
  URL='http://www.sdr-kits.net/DG8SAQ/VNWA-installer.exe';
  Dest= 'd:\VNWA-installer1.exe';
var
  dl: TDownloadURL;
begin
  dl := TDownloadURL.Create(self);
  try
    dl.URL := URL;
    dl.FileName := Dest;
    //dl.OnDownloadProgress := URL_OnDownloadProgress;  //ExecuteTarget cashes if uncommented
    dl.ExecuteTarget(nil); //this downloads the file
    dl.Free;
  except
    dl.Free;
  end;
end;

end.
Das Herunterladen funktioniert, aber wenn ich den OnDownloadProgress zuweise, dann macht der ExecuteTarget eine Exception 'Invalid Enum Value'.

???

mkinzler 5. Nov 2012 12:43

AW: Problem mit TDownloadURL
 
Die Methode hat keine passende Signatur

http://docs.embarcadero.com/products...ressEvent.html

iphi 5. Nov 2012 12:57

AW: Problem mit TDownloadURL
 
Zitat:

Die Methode hat keine passende Signatur
Was bedeutet das? Was kann ich dagegen tun?

himitsu 5. Nov 2012 13:01

AW: Problem mit TDownloadURL
 
Schau dir mal die vorgegebenen Parameter des verwendeten (und von mkinzler verlinkten) Events an und vergleiche diese mit den Parametern deiner Ereignismethode.

mkinzler 5. Nov 2012 13:01

AW: Problem mit TDownloadURL
 
Die Signatur der Methode anpassen.

Delphi-Quellcode:
procedure TForm1.URL_OnDownloadProgress (Sender: TDownLoadURL; Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String; var Cancel: Boolean);

iphi 5. Nov 2012 13:06

AW: Problem mit TDownloadURL
 
Stimmt doch überein!?

Meine Deklaration:
Delphi-Quellcode:
procedure URL_OnDownloadProgress
          (Sender: TDownLoadURL;
           Progress, ProgressMax: Cardinal;
           StatusCode: TURLDownloadStatus;
           StatusText: String; var Cancel: Boolean);
Die vom Link:
Delphi-Quellcode:
TDownloadProgressEvent = procedure (Sender: TDownLoadURL; Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String; var Cancel: Boolean) of object;

Bin ich blind?

iphi 5. Nov 2012 13:09

AW: Problem mit TDownloadURL
 
Zitat:

Die Signatur der Methode anpassen.

procedure TForm1.URL_OnDownloadProgress (Sender: TDownLoadURL; Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String; var Cancel: Boolean);
Hab ich gemacht, das ändert am Fehler nichts. Anscheinend genügt es die Signatur nur einmal (ganz oben) zu definieren.

mkinzler 5. Nov 2012 13:20

AW: Problem mit TDownloadURL
 
Nein, auch bei der Implementation muss man diese angeben. Denn man könnte die Methode auch überladen.

DeddyH 5. Nov 2012 13:25

AW: Problem mit TDownloadURL
 
Unter Delphi XE kann ich den Fehler nicht reproduzieren.

iphi 5. Nov 2012 13:42

AW: Problem mit TDownloadURL
 
Zitat:

Nein, auch bei der Implementation muss man diese angeben. Denn man könnte die Methode auch überladen.
Müsste man dann nicht Overload angeben?

Auf meinem Delphi6 läuft das jedenfalls fehlerfrei:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure Add(i,j: Cardinal; var k: Cardinal);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Add;
begin
k:=i+j;
end;

procedure TForm1.Button1Click(Sender: TObject);
var x: Cardinal;
begin
Add(1,2,x);
Label1.Caption:=inttostr(x);
end;

end.


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:11 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz