Tried to describe most of my problem in the title, and I mostly did.
Basically, I've made my own little TCP Server with Indy 10 in Lazarus. All it does is it accepts packets in form of bytes that contain a certain char
representing a letter from English alphabet. I'm reading these bytes with the Context
s' IOHandler
like this:
procedure TServerSideForm.OnExecuteServer(Context: TIdContext);
var
IO: TIdIOHandler;
keyPressed: char;
begin
//
IO := Context.Connection.IOHandler;
if not(IO.InputBufferIsEmpty) then
begin
LogForm.LogToForm('Recieving a packet from ' + Context.Binding.IP + '(' + Context.Binding.PeerIP + ')');
keyPressed := IO.ReadChar;
AddKeyToAppropriateClient(keyPressed, Context.Binding.IP);
end;
IndySleep(10);
//
end;
And this works perfectly.
However, I've got another form that has a TTabControl
in it, which has a tab for each user connected to my server, there is also a TMemo
in each tab. Tabs and memos are created at runtime and the function that does that, does not throw any exceptions.
Here's how the AddTab()
function from my other form looks like (for creating tabs and memos described above):
procedure TConnectionsForm.AddTab(IP: string);
var
newMemo: TMemo;
begin
ConnectionTabs.Tabs.Add(IP);
currTabIndx := ConnectionTabs.TabIndex;
newMemo := TMemo.Create(ConnectionsForm);
newMemo.AnchorSide[akTop].Side:=asrTop;
newMemo.AnchorSide[akTop].Control:=ConnectionTabs;
newMemo.BorderSpacing.Top:=2;
newMemo.AnchorSide[akBottom].Side:=asrBottom;
newMemo.AnchorSide[akBottom].Control:=ConnectionTabs;
newMemo.BorderSpacing.Bottom:=2;
newMemo.AnchorSide[akLeft].Side:=asrLeft;
newMemo.AnchorSide[akLeft].Control:=ConnectionTabs;
newMemo.BorderSpacing.Left:=2;
newMemo.AnchorSide[akRight].Side:=asrRight;
newMemo.AnchorSide[akRight].Control:=ConnectionTabs;
newMemo.BorderSpacing.Right:=2;
newMemo.Anchors := [akTop, akBottom, akLeft, akRight];
newMemo.Parent := ConnectionTabs;
newMemo.Visible:=true;
newMemo.Lines.Add(IP);
SetLength(connectionMessagesArr, Length(connectionMessagesArr)+1);
connectionMessagesArr[Length(connectionMessagesArr)-1] := newMemo;
ShowOnly(currTabIndx);
end;
It seems to be working fine, I've tested it multiple times on its own.
But when I run that function from my OnConnect
function for my TIdTCPServer
the server process seems to freeze until some other event, like OnExecute
, for example, happens. When OnExecute
does execute, the messages that have been accepted by the process are also executed. For example, if my program freezes, and while it's frozen, I will try to minimize one of my forms and move some other form somewhere else on the screen, they will do that after the program unfreezes.
Here's my own OnConnect
function:
procedure TServerSideForm.OnConnectServer(Context: TIdContext);
begin
LogForm.LogToForm(Context.Binding.IP + ' has connected to the server (' + Context.Binding.PeerIP + ')');
//ConnectionsForm.AddTab(Context.Binding.PeerIP); // Boom
//ConnectionsForm.ConnectionTabs.Tabs.Add('!!'); // Boom
end;
As I've also stated in the title, any kind of interaction with TTabControl
s tabs makes the program freeze. ConnectionsForm.ConnectionTabs.Tabs.Add('!!');
also makes the program freeze (here, ConnectionsTabs
is my TTabControl
variable inside my form called ConnectionsForm
).
I really have no idea to what is going on in here, so some help would really be appreciated.