Thema: Delphi Threads und IdHTTP

Einzelnen Beitrag anzeigen

Capa

Registriert seit: 26. Okt 2003
102 Beiträge
 
RAD-Studio 2010 Arc
 
#1

Threads und IdHTTP

  Alt 14. Aug 2011, 21:15
Hi
ich hab bisher mit Threads noch nix gemacht und nun ein kleines Problem
mit meinem Code, hab schon mehrere seiten durchgeschaut sonst würde der code
nicht so aussehen ^^ ist ne mischung aus verschiedenen gefundenen Beispielen.

Hab immo nur folgende fehlermeldungen:
Code:
[DCC Fehler] Unit5.pas(63): E2037 Deklaration von 'Get' unterscheidet sich von vorheriger Deklaration
[DCC Fehler] Unit5.pas(67): E2003 Undeklarierter Bezeichner: 'THIdHTTP'
[DCC Fehler] Unit5.pas(67): E2003 Undeklarierter Bezeichner: 'xurl'
[DCC Fehler] Unit5.pas(68): E2003 Undeklarierter Bezeichner: 'xfilename'
Ich gehe mal von aus die letzten 3 Fehlermeldungen sind folgefehler durch den ersten, allerdings hab ich ka wie ich den beheben soll.
Hab schon verschiedene sachen ausprobiert allerdings ohne erfolg.

Delphi-Quellcode:
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.
Mfg
  Mit Zitat antworten Zitat