OnExecute updating a Form

Giganews Newsgroups
Subject: OnExecute updating a Form
Posted by:  anomalous (…@thanks)
Date: Wed, 2 Jul 2003

A question about the Chat Room demo:  part of the tcpServerExecute method
includes a call to UpdateClientList.  since this function updates a listbox
on the main form, shouldnt this be done through a Synchronize?  if not, why
is it ok to do this - i thought OnExecute was called in the context of the
thread connected to that particular client...

code fragment:

procedure TfrmMain.UpdateClientList;
var
  Count : Integer;
begin
{ Loop through all the clients connected to the system and set their names }
  for Count := 0 to lbClients.Items.Count -1 do
    if Count < Clients.Count then
      lbClients.Items.Strings[Count] :=
TSimpleClient(Clients.Items[Count]).Name;
end;

procedure TfrmMain.tcpServerExecute(AThread: TIdPeerThread);
var
  Client : TSimpleClient;
  Com,    // System command
  Msg    : String;
begin
{ Get the text sent from the client }
  Msg    := AThread.Connection.ReadLn;
{ Get the clients package info }
  Client := Pointer(AThread.Data);
{ Check to see if the clients name has been assigned yet }
  if Client.Name = 'Logging In' then
    begin
    { if not, assign the name and announce the client }
      Client.Name := Msg;
      UpdateClientList;
      BroadcastMessage('System', Msg + ' has just logged in.');
      AThread.Connection.WriteLn(memEntry.Lines.Text);
    end
.
.
.etc

Replies