使用 Tcollection 在 dephi 中保存 vcl 对象引用

发布于 2024-10-17 06:02:19 字数 342 浏览 9 评论 0原文

我正在使用delphi 2009和VCL组件。我创建了一个名为的集合 TStreets 由项目组成 TStreet 只有两个私有字段。现在我需要添加 到 Tstreet 类的另一个字段/属性来跟踪(通过使用引用) TMyObject 类的其他对象。

一个例子:假设 TStreet 集合包含五个元素和十个对象 (TMyObject) 在运行时存在于我的应用程序中。 TMyObject 的每个对象都可以属于 仅一个 TStreet,因此我需要为每个 TStreet 保存所有对象的引用和 然后能够将一个或多个对象引用从一个 TStreet 移动到另一个。 我应该在 TStreet 下创建另一个集合来保存对象引用吗?

走的路正确吗?

I am using delphi 2009 and VCL components. I have created a collection called
TStreets made of items TStreet which has just two private fields. Now I need to add
to Tstreet class another field/property to keep track (by using reference) of
other objects of class TMyObject.

An example: let's assume that TStreet collection contains five elements and ten objects
(TMyObject) exists in my application at run-time. Each objects of TMyObject can belong
to only one TStreet so I need to save for each TStreet all reference of objects and
then be able to move one or more object reference from one TStreet to another.
Should I create another colletion under TStreet where saving object references?

Is it correct the way to go?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十二 2024-10-24 06:02:19

鉴于以下情况。

TMyObject = class
  ...
end;

TStreet = class
 ...
 public
   property MyObject : TMyObject ...;
end;

TStreets = TList<TStreet>;

从阅读你的问题来看,一个 TMyObject 只能绑定到一个 TStreet 。

然后我建议反转参考文献。

TStreet = class;

TMyObject = class
protected
  FStreet : TStreet;
public
  property Street : TStreet read FStreet write FStreet;
end;

TMyObjectList = TList<TMyObject>;

TStreet = class
 private
   // Looks through MyObjectList returning correct 
   function GetMyObjecty : TMyObject; reference.
 public
   property MyObject : TMyObject read GetMyObject;
   // Reference to list that contains all instance of TMyObjectList.
   property MyObjectList : TMyObjectList; 
end;

TStreets = TList<TStreet>;

TMyObjectList = TList<TMyObject>;

Given the following.

TMyObject = class
  ...
end;

TStreet = class
 ...
 public
   property MyObject : TMyObject ...;
end;

TStreets = TList<TStreet>;

It appears from reading your question that a TMyObject can only be tied to one TStreet.

Then I would recommend reversing the references.

TStreet = class;

TMyObject = class
protected
  FStreet : TStreet;
public
  property Street : TStreet read FStreet write FStreet;
end;

TMyObjectList = TList<TMyObject>;

TStreet = class
 private
   // Looks through MyObjectList returning correct 
   function GetMyObjecty : TMyObject; reference.
 public
   property MyObject : TMyObject read GetMyObject;
   // Reference to list that contains all instance of TMyObjectList.
   property MyObjectList : TMyObjectList; 
end;

TStreets = TList<TStreet>;

TMyObjectList = TList<TMyObject>;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文