unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls;
type
TCallBack =
Procedure(
Const Content:
String)
of object;
TTestThread=Class(TThread)
Private
FS:
String;
FCallBack:TCallBack;
procedure Showtext;
public
constructor Create( CreateSuspended : Boolean;CallBack:TCallBack );
overload;
destructor Destroy;
override;
Procedure Execute;
override;
End;
TForm1 =
class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
procedure CallBack(
const s:
String);
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CallBack(
Const s:
String);
begin
Memo1.Lines.Add(s)
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TTestThread.Create(false,CallBack);
end;
{ TTestThread }
constructor TTestThread.Create(CreateSuspended: Boolean;CallBack:TCallBack);
begin
inherited Create(CreateSuspended);
FreeOnTerminate := true;
FCallBack := CallBack;
end;
destructor TTestThread.Destroy;
begin
inherited;
end;
procedure TTestThread.Showtext;
begin
if Assigned(FCallBack)
then FCallBack(FS);
end;
procedure TTestThread.Execute;
var
IdHTTP1 : TIdHTTP;
ss:TStringStream;
begin
inherited;
ss:=TStringStream.Create;
IdHTTP1:= TIdHTTP.Create(
nil);
try
IdHTTP1.Get('
http://www.google.de',ss);
ss.Position := 0;
FS := ss.ReadString(ss.Size);
Synchronize(Showtext);
finally
ss.Free;
IdHTTP1.Free;
end;
end;
end.