Let's say I have a class that declares a local type like this:
type
TAncestor = class
type
TLocalType = (just, some, example);
end;
Then, I want to use that local type in a subclass. However, the following doesn't compile.
type
TChild = class (TAncestor)
procedure Test (AVariable: TLocalType); // error: undeclared identifier: 'TLocalType'
end;
In order to use the type, it seems a fully qualified type name is needed. The following compiles:
type
TChild = class (TAncestor)
procedure Test (AVariable: TAncestor.TLocalType);
end;
While this works, it feels rather unelegant. (Also, if I ever want to change the ancestor of TChild, I'd have to change the class name in both lines.) I'm probably missing something; what's the reason for the type declaration not simply being inherited from the ancestor?
question from:
https://stackoverflow.com/questions/65860291/why-arent-local-type-declarations-inherited 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…