Yes I tested idTCPClient, it works fine, thank you!
Then I decided to try idTCPServer on the client side and tested the code:
procedure TMainForm.UniFormCreate(Sender: TObject);
begin
idServer := TIdTCPServer.Create;
idServer.OnExecute := idServerExecute;
idServer.DefaultPort := 12345;
idServer.Active := True;
UniLabel2.Caption := 'Test';//Works fine
end;
procedure TMainForm.idServerExecute(AContext: TIdContext);
var
i: integer;
begin
with AContext.Connection.Socket do
try
i := ReadLongint;
UniLabel2.Caption := inttostr(i);//Exception
except
end;
end;
This code gives an exception "Attempt to access nil session reference" while referencing UniLabel2. Why is that?
I guess this relates to the fact that idServerExecute is executed by Indy in a thread, but why "session is nil"?
And another question, VCL components are not thread safe, is the situation the same with UniGui controls?