unit Unit5;
interface
uses
Classes ,Windows ,IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP;
type
TThreadedProc=
procedure(xurl, xfilename:
String);
type
IdhttpThread =
class(TThread)
THIdHTTP: TIdHTTP;
procedure IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
procedure IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64);
private
FParam1 :
String;
FParam2 :
String;
FProc : TThreadedProc;
{ Private declarations }
protected
procedure Execute;
override;
public
{ Public declarations }
property Param1 :
String read FParam1
write FParam1;
property Param2 :
String read FParam2
write FParam2;
property GET : TThreadedProc
read FProc
write FProc;
constructor Create(CreateSuspended: Boolean);
destructor Destroy;
override;
end;
implementation
uses Unit1;
{ Download }
constructor IdhttpThread.Create(CreateSuspended: Boolean);
begin
inherited;
THIdHTTP := TIdHTTP.Create(
nil);
end;
destructor IdhttpThread.Destroy;
begin
THIdHTTP.Free;
inherited;
end;
procedure IdhttpThread.Execute;
begin
THIdHTTP.OnWork := IdHTTP1Work;
THIdHTTP.OnWorkBegin := IdHTTP1WorkBegin;
try
GET(FParam1, FParam2);
except
end;
{ Thread-Code hier einfügen }
end;
procedure IdhttpThread.Get(xurl, xfilename:
String);
var x : TStringList;
begin
x := Tstringlist.Create;
x.Text := THIdHTTP.Get(xurl);
x.SaveToFile(xfilename);
end;
procedure IdhttpThread.IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
begin
if Form1.updatestatus = 1
then
Form1.ProgressBar1.Position := AWorkCount;
if Form1.updatestatus = 2
then
Form1.ProgressBar2.Position := AWorkCount;
if Form1.updatestatus = 3
then
Form1.ProgressBar3.Position := AWorkCount;
end;
procedure IdhttpThread.IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
begin
if Form1.updatestatus = 1
then
Form1.ProgressBar1.Max := AWorkCountMax;
if Form1.updatestatus = 2
then
Form1.ProgressBar2.Max := AWorkCountMax;
if Form1.updatestatus = 3
then
Form1.ProgressBar3.Max := AWorkCountMax;
end;
end.