Richtig, es wird leider keine
Exception geworfen.
Die gewüschnte Beispiel-Implementierung wäre:
Delphi-Quellcode:
uses classes,urlmon,Dialogs;
type
TThreadDownload =
class (TThread)
protected
fileURL,filePath :
string;
procedure Execute;
override;
procedure info;
public
downloadSuccess : integer;
constructor create (
url,path :
string; suspended : boolean);
procedure FreeInstance;
override;
end;
implementation
constructor TThreadDownload.create (
url,path:
string; suspended : boolean);
begin
inherited create (suspended);
fileURL :=
url;
filePath := path;
end;
procedure TThreadDownload.Execute;
begin
// Download starten und Ergebnis notieren
downloadSuccess := urlDownloadToFile (
nil,pchar (fileURL),pchar (filePath),0,
nil);
end;
procedure TThreadDownload.info;
begin
showmessage ('
Free!');
end;
procedure TThreadDownload.FreeInstance;
begin
inherited FreeInstance;
synchronize (info);
end;
für den Download-Thread und
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
//
// Download-Thread starten
//
begin
Thread1 := TThreadDownload.create ('
http://upload.wikimedia.org/wikipedia/en/d/d4/Delphi_Composite.jpg','
c:\delphi1.jpg',false);
Thread1.FreeOnTerminate := true;
end;
procedure TForm1.Button2Click(Sender: TObject);
//
// Kill
//
begin
// Download-Thread über die WinAPI abschießen
Thread1.Suspend;
TerminateThread (Thread1.Handle,Thread1.ThreadID);
Thread1.Free;
end;
als Test-Beispiel.