Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   winnet download thread (https://www.delphipraxis.net/185221-winnet-download-thread.html)

drama22 23. Mai 2015 13:03

AW: winnet download thread
 
Zitat:

Zitat von Luckie (Beitrag 1302761)
Add some pubic fields to your thread object for the parameters.

do you mean i have to do something like this

Delphi-Quellcode:
TDownloadThread = class(TThread)
public
  Url: string;
  ms: TMemoryStream;
  procedure Execute; override;
  procedure DownloadToStream;
end;
thats really makes me lost some how

Luckie 23. Mai 2015 13:07

AW: winnet download thread
 
Exactly.

drama22 23. Mai 2015 13:12

AW: winnet download thread
 
Zitat:

Zitat von Luckie (Beitrag 1302763)
Exactly.

and how could i download and save to memory stream then usually i do this with my procedure
Delphi-Quellcode:
DownloadToStream(strFile, ms);// start downloading file to stream

Luckie 23. Mai 2015 13:40

AW: winnet download thread
 
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.


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

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