Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 May : Use of TTimer with Indy TIDTcpClient
| Subject: | Use of TTimer with Indy TIDTcpClient |
| Posted by: | "Marais" (mara..@x.y) |
| Date: | Mon, 28 May 2007 19:04:15 GMT |
Hi, all-
I have an app which needs to poll a web site every minute or so. I'm using a
TTimer to pace the poll (the exact time is not at all critical).
In the event handler for the timer, I PostMessage to the main form:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
PostMessage(Form1.Handle, WM_Timer1, 0, 0)
end;
A message handler in the main form then executes the Client.Connect method:
procedure TForm1.HandleTimer1(var Message: TMessage);
begin
GetDataFromServer;
end;
procedure TForm1.GetDataFromServer;
begin
try
Client1.connect(5000);
except
on e:exception do PostMessage(Form1.Handle, WM_ConnectFailed, 0, 0)
end;
end;
I use a similar method to respond to the OnConnect event to do the
Client.Writeln and Client.Readln to request and receive the data.
I go through all this to ensure that the client methods are called only from
the main thread and not from some other thread, which may be active when the
events take place. Is this a reasonable way to approach this?
The reason I ask is that my main form is exhibiting a disturbing symptom: a
TMemo in the main form is not repainting itself 100% when I slide another
window over my form. Some artifacts remain, notably in the lower right
corner between the vertical and horizontal scroll bars.
Any thoughts?
Peter