What's the proper way of destroying TIdContext
descendant from the outside? I want to close a particular (hanging) connection and destroy its context.
Say, I'm taking an element from TIdCustomTCPServer.Contexts
and... Calling Free
is not enough I guess. I just want to avoid any pitfalls. Sometimes Indy is not intuitive at all.
You probably want to use something like this. Do not free any context
var
i: Integer;
list: TList;
begin
list := IdTCPServer1.Contexts.LockList;
try
for i := 0 to list.Count-1 do
begin
try
TIdContext(list.Items[i]).Connection.Disconnect;
except
end;
end;
finally
IdTCPServer1.Contexts.UnlockList;
end;
end;