如何使 TObjectDictionary.Values 作为属性可访问?
我有一个像这样的对象:
TMyObj = class
private
FObjList: TObjectDictionary <integer, TMyObject>;
public
constructor Create;
destructor Destroy;
// How to access Values correctly? Something similar to this not working code
property Values: TValueCollection read FObjList.Values write FObjList.Values;
end;
var MyObj: TMyObj;
要访问 FObjList 的值,我想写:
for tmpObject in MyObj.Values do
...
我需要如何声明属性“Values”,以便 MyObj.Values 的行为与访问 MyObj.FObjList.Values 完全相同?
I have an object like this:
TMyObj = class
private
FObjList: TObjectDictionary <integer, TMyObject>;
public
constructor Create;
destructor Destroy;
// How to access Values correctly? Something similar to this not working code
property Values: TValueCollection read FObjList.Values write FObjList.Values;
end;
var MyObj: TMyObj;
To access the values of FObjList, I'd like to write:
for tmpObject in MyObj.Values do
...
How do I need to declare the property "Values" so that MyObj.Values behaves exactly as if I would access MyObj.FObjList.Values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TValueCollection 是 TDictionary 的嵌套类,必须进行限定。并且您最好为 Values 指定一个 getter 方法。
编辑: 起来!太晚了……但略有不同。
TValueCollection is a nested class of TDictionary and has to be qualified. And you better specify a getter method for Values.
Edit: Ups! Too late... But slightly different.