AW: winnet download thread
23. Mai 2015, 14:40
Delphi 2006 code:
Delphi-Quellcode:
type
TDownloadThread = class(TThread)
public
FFilename: AnsiString;
FURL: AnsiString;
procedure Execute; override;
private
procedure DownloadToStream;
end;
// ...
procedure TDownloadThread.DownloadToStream;
var
FileStream: TFileStream;
begin
FileStream := TFileStream.Create(FFilename, fmCreate);
try
// download code goes here
// download from FURL
finally
FileStream.Free;
end;
end;
procedure TDownloadThread.Execute;
begin
inherited;
DownloadToStream;
end;
procedure TForm4.btn1Click(Sender: TObject);
var
DownloadThread: TDownloadThread;
begin
DownloadThread := TDownloadThread.Create(True);
try
DownloadThread.FFilename := 'Z:\test.txt';
DownloadThread.FURL := '....';
DownloadThread.Execute;
finally
DownloadThread.Free;
end;
end;
In later BDS versions TThread provides better/different thread handling.
Michael Ein Teil meines Codes würde euch verunsichern.
Geändert von Luckie (23. Mai 2015 um 14:47 Uhr)
|