function TfrmMainForm.GetSelectedConnection: TIdTCPConnection;
var
PairEnum: TObjectDictionary
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
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.050226211547852 seconds