Her er et fungerende eks. der henter siden
www.google.dk hver 10. sekund og smider teksten i en Memo.
Smid en TMemo og en TTimer på en form.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
Memo1: TMemo;
Timer: TTimer;
procedure TimerTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure HentSideThreadDone(Sender: TObject);
end;
THentSideThread = class(TThread)
private
{ Private declarations }
FHttp : string;
IdHTTP : TIdHTTP;
protected
procedure Execute; override;
public
Indhold : string;
constructor Create(Http : string);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TUpdateCheckThread }
constructor THentSideThread.Create(Http : string);
begin
inherited Create(False);
FreeOnTerminate:=true;
FHttp:=Http;
Indhold:='Error';
end;
procedure THentSideThread.Execute;
begin
try
IdHTTP:=TIdHTTP.Create(nil);
IdHTTP.ReadTimeout:=15000;
IdHTTP.AllowCookies:=false;
Indhold:=IdHTTP.Get(FHttp);
finally
IdHTTP.Free;
end;
end;
{ THKUpdateCheck }
procedure TForm1.HentSideThreadDone(Sender: TObject);
begin
Memo1.Lines.Text:=(Sender as THentSideThread).Indhold;
Timer.Enabled:=true;
end;
procedure TForm1.TimerTimer(Sender: TObject);
begin
Timer.Enabled:=false;
THentSideThread.Create('
http://www.google.dk').OnTerminate:=HentSideThreadDone;
end;
end.