I just faced a strange compiler error when trying to define nested generic record.
Nesting works fine with classes and interfaces, but not with records somehow.
type
TRec<T> = record
Value: T;
end;
TCls = class
public
Rec: TRec<TRec<Integer>>;
end;
This is not compiled on Delphi Berlin 10.1.2 and also no luck on Tokyo 10.2.3. Is this a limitation of language or a compiler issue?
The error message is:
[dcc32 Error] Project1.dpr(22): E2564 Undefined type 'TRec<T>'
I just wanted once to nest the Spring.Nullable<>
types and that did not work. After that I quickly reproduced that with a simple generic record.
TCls = class private type Trec1<T1> = record Value : T1; end; public Rec: TRec<TRec1<Integer>>; end;
– BybeeTRec
did you! LURD is proposing the exact same workaround as can be found in my answer. – MartinemartineauTRecInteger = TRec<Integer>;
and later, in the class:Rec: TRec<TRecInteger>;
? I can't test this (no Delphi here), but I guess it compiles. That is the first thing I would try. – BergrenTRecRecInteger = TRec<TRecInteger>;
does, nor does making the class genericTCls<T> = class
. – Bergren