德尔福 – 做TList>需要免费吗?
发布时间:2020-12-15 04:14:32 所属栏目:大数据 来源:网络整理
导读:我写了代码 procedure Pair;var PairList: TListTPairUInt32,UInt32; LPair: TPairUInt32,UInt32;begin PairList := TListTPairUInt32,UInt32.Create; try PairList.Add(LPair.Create(4,10)); finally PairList.Free; end;end; 当我释放PairList时,我创建的P
我写了代码
procedure Pair; var PairList: TList<TPair<UInt32,UInt32>>; LPair: TPair<UInt32,UInt32>; begin PairList := TList<TPair<UInt32,UInt32>>.Create; try PairList.Add(LPair.Create(4,10)); finally PairList.Free; end; end; 当我释放PairList时,我创建的Pair也需要被释放? 解决方法
您不必释放TPair变量,因为它是一个值类型 – 声明为的记录
TPair<TKey,TValue> = record Key: TKey; Value: TValue; constructor Create(const AKey: TKey; const AValue: TValue); end; 如果您尝试使用LPair.Free释放它,您将收到编译器错误
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |