Die
VCL ist nicht Threadsicher, benutze deshalb Kritische Abschnitte.
Delphi-Quellcode:
uses ..., SyncObjs;
type
:
private
{ Private-Deklarationen }
FCriticalSection:TCriticalSection;
:
end;
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
FCriticalSection:=TCriticalSection.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FCriticalSection.free;
end;
procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
:
begin
:
FCriticalSection.Enter;
try
ListView1.Clear;
List := IdTCPServer1.Contexts.LockList;
for i := 0 to List.Count - 1 do begin
TidContext(List.Items[i]).Connection.IOHandler.WriteLn(text);
with Listview1.Items.Add do
caption := TIdContext(List.Items[i]).Connection.Socket.Binding.PeerIP;
end;
IdTCPServer1.Contexts.UnlockList;
finally
FCriticalSection.Leave;
end;
end;