本文整理自网络,侵删。
function TfrmMainForm.GetSelectedConnection: TIdTCPConnection;
var
PairEnum: TObjectDictionary.TPairEnumerator;
Conn: TIdTCPConnection;
IPS:STRING;
begin
//从列表中选择,返回 TIdTCPConnection;为后续的关闭做准备
ReportMemoryLeaksOnShutdown := True;//开启内存泄漏报告模式
try
if ServerContainer1.FTCPConnection =nil then
begin
showmessage('ServerContainer1.FTCPConnectio =nil');
end;
PairEnum := ServerContainer1.FTCPConnection.GetEnumerator;
while PairEnum.MoveNext do
begin
ips := PairEnum.Current.Key;
if L_UserLink.Selected=nil then
exit;
if L_UserLink.Selected.SubItems[0]=ips then
result:=PairEnum.Current.Value;
end;
finally
PairEnum.CleanupInstance;
{一般人没有加上面这行代码所以会报错 An unexpected memory leak has occured. the unexpected smal block leaks are
解决办法是在FREE之前加 CleanupInstance;
}
PairEnum.Free;
end;
end;
来源:https://blog.csdn.net/qq_25439957/article/details/88635643
相关阅读 >>
更多相关阅读请进入《Delphi》频道 >>