Reputation: 10372
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?
Upvotes: 0
Views: 383
Reputation: 12114
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;
Upvotes: 0
Reputation: 84650
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.
Upvotes: 2