Strange OnConnected corner case

Hi guys,

An interesting corner case Im experiencing. Delphi Tokyo 10.2.3 Latest RO.

if i do something like

fChannel := TROTransportChannel.ChannelMatchingTargetUrl(‘supertcp://localhost:8090/Bin’);
fMessage := TROMessage.MessageMatchingTargetUrl(‘supertcp://localhost:8090/Bin’);
TROBaseSuperTcpChannel(fChannel).OnConnected := OnConnected;
TROBaseSuperTcpChannel(fChannel).OnDisConnected := OnDisconnected;
TROBaseSuperTcpChannel(fChannel).AutoReconnect := True;

Where

fChannel: TROTransportChannel;
fMessage: TROMessage;

On the OnCreate of a form and the two above variables are on its private section and the events are something like:

procedure TForm2.OnConnected(Sender: TObject);
begin
Memo1.Lines.Add(‘Connected’);
end;

If I put a button and add the following code:

procedure TForm1.BitBtn1Click(Sender: TObject);
var
lCoreService : IService;

begin
lCoreService := CoService.Create(fMessage, fChannel);
If lCoreService.GetTime then
Memo1.Lines.Add(‘IsResponding’);
end;

It will go to the OnConnected event, add the line on the Memo1 and then it will hang until it gets a Timeout message.

The problem goes away if prior to call anything I do a fChannel.Active := True and then execute further calls.

The behaviour I’ll expect is to trigger the OnConnected and execute the remote call.

SuperTCPChannel events are fired not synchronized (SynchronizeEvents = false, by default) and it causes some problems with your code: you are trying to modify GUI element (Memo1) from background thread.

as a workaround, I can suggest to use solution from server-side of the MegaDemo sample, where such log messages are posted from background threads with PostMessage