Thema: Delphi Indy freeze Problem

Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#15

Re: Indy freeze Problem

  Alt 20. Feb 2009, 23:52
Also ich weiß nicht wo das Problem ist. Du erstellst eine Thread-Klasse von TThread abgeleitet. Dieser fügst du ein neues Property URL hinzu. In der Execute-Methode erstellst du die Indy-Komponente und gibst sie am Ende wieder frei:
Delphi-Quellcode:
unit Unit3;

interface

uses
  Classes;

type
  TDownloadThread = class(TThread)
  private
    { Private-Deklarationen }
    FURL: string;
    FCode: string;
    procedure ShowCode;
  public
    property URL: string read FURL write FURL;
  protected
    procedure Execute; override;
  end;

implementation

uses
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, Unit2;

{ TDownloadThread }

procedure TDownloadThread.Execute;
var
  IdHTTP: TIdHTTP;
begin
  IdHTTP := TIdHTTP.Create(nil);
  try
    FCode := IdHTTP.Get(URL);
  finally
    IdHTTP.Free;
  end;
  Synchronize(ShowCode);
end;

procedure TDownloadThread.ShowCode;
begin
  Form2.Memo1.Text := FCode;
end;

end.
Und der Aufruf:
Delphi-Quellcode:
uses
  Unit3;

procedure TForm2.Button1Click(Sender: TObject);
var
  DownloadThread: TDownloadThread;
begin
  DownloadThread := TDownloadThread.Create(True);
  DownloadThread.FreeOnTerminate := True;
  DownloadThread.URL := 'http://www.michael-puff.de';
  DownloadThread.Resume;
end;
Das sollte als Grundgerüst reichen. Das ganze kann man jetzt noch um eine Fortschrittsanzeige und die Möglichkeit das ganze abzubrechen erweitern.abzubrechen
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat