如何更新 TList中的数据?
我有这个记录(结构):
type
THexData = record
Address : Cardinal;
DataLen : Cardinal;
Data : string;
end;
我已经声明了这个列表:
HexDataList: TList<THexData>;
我已经用一些数据填充了列表。现在我想扫描 ListHexData,有时会更新 HexDataList 内的记录元素。
是否可以?我该怎么办?
I have this record (structure):
type
THexData = record
Address : Cardinal;
DataLen : Cardinal;
Data : string;
end;
And I've declared this list:
HexDataList: TList<THexData>;
I've filled the list with some data. Now I'd like scan ListHexData and sometimes update a element of a record inside HexDataList.
Is it possible? How can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
绑定是您想要就地修改
HexDataList[i]
,但您不能。当我使用保存记录的TList
时,我实际上对TList
进行了子类化,并将Items
属性替换为返回指向该项目的指针,而不是该项目的副本。这允许就地修改。编辑
再次查看我的代码,我意识到我实际上并没有对
TList
进行子类化,因为该类太私有,无法提取指向底层数据的指针。这或许是一个不错的决定。我实际上所做的是实现我自己的通用列表类,这使我可以在需要时自由返回指向记录的指针。The bind is that you would like to modify
HexDataList[i]
in place, but you can't. When I'm working with aTList<T>
that holds records I actually sub-classTList<T>
and replace theItems
property with one that returns a pointer to the item, rather than a copy of the item. That allows for inplace modification.EDIT
Looking at my code again I realise that I don't actually sub-class
TList<T>
because it the class is too private to extract pointers to the underlying data. That's probably a good decision. What I actually do is implement my own generic list class and that allows me the freedom to return pointers to records if needed.