views:

75

answers:

3

I'd like to create a nested class which is based on the type provided to the outer class. I need the inner class to extend T by some members:

TOuterClass<T:class> = class
  type
    TNestedClass = class(T)
      MoreData:Integer;
    end;
end;

The compiler says "No" or more specifically [DCC Error] MyUnit.pas(20): E2021 Class type required at class(T).

Is it somehow possible to achieve what I am trying to do?

+6  A: 

No, that's not possible.

Barry Kelly
A pity, but good to know for sure. Thanks.
Heinrich Ulbricht
+2  A: 

Not yet. It probably should, but the compiler doesn't really think through all the ramifications of generic constraints yet. You should add this into QC as a feature request.

Mason Wheeler
A: 

No but you can in a derived class that has resolved the type of T:

TOuterClass<T:class> = class
  //Data
end;

TDerived = class(TOuterClass<TObject>)
  type
    TNestedClass = class(TObject)
      MoreData:Integer;
    end;
end;
codeelegance