Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Apr : TIdTCPClient.OnDisconnected not triggering
| Subject: | TIdTCPClient.OnDisconnected not triggering |
| Posted by: | "Bince" (foahch..@hotmail.com) |
| Date: | 25 Apr 2006 14:09:20 |
Hi, I have just an IdTCPClient and a memo on a form displaying the text received by the IdTCPClient. The problem is, the OnDisconnected event doesn't seem to be doing anything. The "DISCONNECTED" text doesn't display in the memo, and I'm not sure whether the thread used for reading the received text is being freed or not. Here's the relevant code:
constructor TReadingClass.Create(AConn: TIdTCPConnection);
begin
FConn := AConn;
inherited Create(False);
end;
procedure TReadingClass.Execute;
var
Line: String;
begin
while not Terminated and FConn.Connected do
begin
Line := FConn.IOHandler.ReadLn;
if (Line <> '') then Form1.Memo1.Lines.Add(Line);
end;
end;
procedure TForm1.IdTCPClient1Connected(Sender: TObject);
begin
rt := TReadingClass.Create(IdTCPClient1);
end;
procedure TForm1.IdTCPClient1Disconnected(Sender: TObject);
begin
rt.Terminate;
rt.WaitFor;
FreeAndNil(rt);
Memo1.Lines.Add('*** DISCONNECTED ***');
end;
Can anyone help me out here? Thanks.