Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Edit</strong>: back behind a PC.</p> <p>The classic way of maintaining lists of predetermined objects of a certain class is using <a href="http://docwiki.embarcadero.com/VCL/en/Classes.TCollection" rel="nofollow noreferrer">TCollection</a>/<a href="http://docwiki.embarcadero.com/VCL/en/Classes.TCollectionItem" rel="nofollow noreferrer">TCollectionItem</a>.</p> <p>TCollection/TCollectionItem are heavily used in Delphi (see <a href="http://docwiki.embarcadero.com/VCL/en/Classes.TCollection" rel="nofollow noreferrer">this list</a>). They are lighter weight than <a href="http://docwiki.embarcadero.com/VCL/en/Classes.TComponent" rel="nofollow noreferrer">TComponent</a> (that automatically maintains <a href="http://docwiki.embarcadero.com/VCL/en/Classes.TComponent.Owner" rel="nofollow noreferrer">Owner</a>/<a href="http://docwiki.embarcadero.com/VCL/en/Classes.TComponent.Components" rel="nofollow noreferrer">Components</a>/<a href="http://docwiki.embarcadero.com/VCL/en/Classes.TComponent.ComponentCount" rel="nofollow noreferrer">ComponentCount</a> and has <a href="http://docwiki.embarcadero.com/VCL/en/Classes.TComponent.FreeNotification" rel="nofollow noreferrer">FreeNotification</a>), as TCollectionItem and TCollection both descend from <a href="http://docwiki.embarcadero.com/RADStudio/en/TPersistent_Branch" rel="nofollow noreferrer">the TPersistent branch</a> in stead of <a href="http://docwiki.embarcadero.com/RADStudio/en/TComponent_Branch" rel="nofollow noreferrer">TComponent branch</a>.<br> TCollection has a nice virtual <a href="http://docwiki.embarcadero.com/VCL/en/Classes.TCollection.Notify" rel="nofollow noreferrer">Notify</a> method: </p> <pre><code>procedure TCollection.Notify(Item: TCollectionItem; Action: TCollectionNotification); begin case Action of cnAdded: Added(Item); cnDeleting: Deleting(Item); end; end; </code></pre> <p>From Delphi 2009, you have generics, so then it can pay off big time to use <a href="http://docwiki.embarcadero.com/VCL/en/Generics.Collections.TList" rel="nofollow noreferrer">TList</a> (in your cast <code>TList&lt;TEntity&gt;</code>, as it contains this very nice <a href="http://docwiki.embarcadero.com/VCL/en/Generics.Collections.TList.Notify" rel="nofollow noreferrer">Notify</a> method and <a href="http://docwiki.embarcadero.com/VCL/en/Generics.Collections.TList.OnNotify" rel="nofollow noreferrer">OnNotify</a> event:</p> <pre><code>procedure TList&lt;T&gt;.Notify(const Item: T; Action: TCollectionNotification); begin if Assigned(FOnNotify) then FOnNotify(Self, Item, Action); end; </code></pre> <p>These two solutions work well if your <code>TMesh</code> is indeed a collection/list of <code>TEntity</code>.<br> If it <code>TMesh</code> is a non-list graph of <code>TEntity</code>, then it is better to descend both from <a href="http://docwiki.embarcadero.com/VCL/en/Classes.TComponent" rel="nofollow noreferrer">TComponent</a> like vcldeveloper<a href="https://stackoverflow.com/users/48789/vcldeveloper">link text</a> explained in <a href="https://stackoverflow.com/questions/4530364/referencing-a-class-inside-another-class-by-address/4530497#4530497">his answer</a>.</p> <p><a href="http://www.andypatterns.com/" rel="nofollow noreferrer">Andy Bulka</a> has a nice blog post on the various ways of using <a href="http://www.atug.com/andypatterns/collections.htm" rel="nofollow noreferrer">lists and collections</a>, including a well balanced view of <a href="http://www.atug.com/andypatterns/collections.htm#TCollectionMerits" rel="nofollow noreferrer">TCollection/TCollectionItem usage</a>.</p> <p>--jeroen</p> <p><em>Old answer</em> (great iPad auto-complete bugs fixed):</p> <p>Sorry for the short answer, as I am on the road only carrying a mobile device.</p> <p>It looks like your mesh is a container for entities.<br> If so, then you should look into TCollection and TCollectionItem.<br> Derive your mesh from the former and your entity from the latter.</p> <p>The delphi vcl source code contain many examples of these: fields/field or actions/action are good starters.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload