I create two units and put the first class in one of them:
unit UBaseClass; interface type TBaseOuterClass = class protected type TBaseInnerClass = class public end; protected function GetInnerInstance: TBaseOuterClass.TBaseInnerClass; virtual; end; implementation { TBaseOuterClass } function TBaseOuterClass.GetInnerInstance: TBaseOuterClass.TBaseInnerClass; begin
And I put the derived class in the second block:
unit UDerClass; interface uses UBaseClass; type TDerOuterClass = class(TBaseOuterClass) protected type TDerInnerClass = class(TBaseInnerClass) end; protected function GetInnerInstance: TBaseOuterClass.TBaseInnerClass; override; end; implementation { TDerOuterClass } function TDerOuterClass.GetInnerInstance: TBaseOuterClass.TBaseInnerClass; begin end; end.
When I try to compile, I get
[dcc32 error] UDerClass.pas (22): E2362 Unable to access protected character TBaseOuterClass.TBaseInnerClass
in the line function TDerOuterClass.GetInnerInstance: TBaseOuterClass.TBaseInnerClass;
I do not understand why TBaseOuterClass.TBaseInnerClass (as an internal protected class) is not available from TDerOuterClass (which is obtained for TBaseOuterClass). What are the types actually protected in this case?
I did not find any explanation for this in the topic of declarations of nested types . So are there any reasons for this behavior?
This also applies to simple protected types, e.g.
protected type TSimpleType = Integer;
I can not write a function in TDerOuterClass
protected function GetValue: TSimpleType;
since i get the message
[dcc32 error] UDerClass.pas (16): E2003 Undeclared identifier: 'TSimpleType'
delphi delphi-xe6
tikskit
source share