title: How to implement TCollection and TCollectionItem functionality in generics
body: <p>I'm trying to implement <code>TCollection</code> and <code>TCollectionItem</code> functionality in generics. To solve this problem we need to make a forward declaration of <code>TGenericCollectionItem</code> or <code>TGenericCollection</code>. Using forward declaration of a generic type is not supported by the actual (XE6) Delphi compiler. <a href="https://stackoverflow.com/questions/6055742/how-to-set-a-forward-declaration-with-generic-types-under-delphi-2010">There is a hack</a> how to make it. But we still have a problem with assigning an Owner to <code>TCollectionItem</code>.</p>
  
  <pre><code>  TBaseElement = class // hack for forward declaration of a generic type 
    end;
  
    TGenericCollection&lt;T: TBaseElement&gt; = class(TObjectList&lt;TBaseElement&gt;)
    protected
      procedure Notify(const Value: TBaseElement; Action: TCollectionNotification); override;
    end;
  
    TGenericCollectionItem = class(TBaseElement)
    public
      Owner: TGenericCollection&lt;TBaseElement&gt;;
    end;
  
    procedure TGenericCollection&lt;T&gt;.Notify(
      const Value: TBaseElement; Action: TCollectionNotification);
    begin
      inherited;
  
      if (Action = cnAdded) then
      begin
        if (Value is TGenericCollectionItem) then
          (Value as TGenericCollectionItem).Owner := Self;  //here is error
      end;
    end;
  </code></pre>
  
  <blockquote>
    <p>E2010 Incompatible types: <code>'TGenericCollection&lt;TBaseElement&gt;'</code> and <code>'TGenericCollection&lt;TGenericCollection&lt;T&gt;.T&gt;'</code></p>
  </blockquote>
  
  <p>How to solve this conflict?</p>