[fpc-devel] Exact rules for "strict protected"

Martin Frb lazarus at mfriebe.de
Wed Feb 14 15:00:10 CET 2024


https://www.freepascal.org/docs-html/ref/refse35.html
>
> Strict Protected
>     Is the same as Protected, except that the members of a Protected
>     section are also accessible to other classes implemented in the
>     same unit. Strict protected members are only visible to descendent
>     classes, not to other classes in the same unit. 
>


In the below

TSubFoo can see the strict proctected TTest.
So therefore TSubFoo does not count as "not to other classes in the same 
unit."
Well, it is another class, but it is within the class TFoo.

TSubBar is also another class, but it is within TBar. And for TBar we 
have "only visible to descendent classes" => TBar should see TTest.
And since TSubBar is in TBar?

So the below code have that error, or is it a bug?
An if it should, what is the correct exact description of "Strict 
protected"?


program Project1;
type
   TFoo = class
   strict protected type
     TTest = record end;
   private type
     TSubFoo = class
       a: TTest;
     end;
   end;

   TBar = class(TFoo)
   private type
     TSubBar = class
       a: TTest;  // project1.lpr(15,10) Error: Identifier not found "TTest"
     end;
   end;

begin
end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20240214/2f6bd246/attachment.htm>


More information about the fpc-devel mailing list