Saving vcl objects references in dephi with Tcollection

纵饮孤独 提交于 2019-12-06 13:42:25

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>;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!