[fpc-devel] composed record with private/public => documented behaviour?
Mattias Gaertner
nc-gaertnma at netcologne.de
Wed Oct 28 08:37:58 CET 2026
On 10/28/26 07:47, Martin Frb via fpc-devel wrote:
> The fields of the embedded record become available in the outer record.
> What visibility do they get (I can and have tested, and results make
> sense / but I want to know, if that is the designed / documented behaviour)
>
>[...]
> - fields are the lowest of both? E.g. 2 access rules must both be passed
> to access
lowest of both
So a strict private of an inner field is not visible to the outer
record, even in the same unit. It still uses space.
> Also what if the outer record is NOT advanced? and does not have
> visibility? (that I have not tested yet)
Default is public.
> unit Unit2; {$mode ObjFPC}{$H+}
> {$ModeSwitch advancedrecords} {$ModeSwitch recordcomposition}
> interface
> type
> T1 = record
> private a,b: integer;
> public c,d: integer;
> end;
>
> unit Unit1; {$mode ObjFPC}
> {$ModeSwitch advancedrecords} {$ModeSwitch recordcomposition}
> interface
> uses unit2;
> type
> T2 = record
> private
> contains T1;
> end;
>
> T3 = record
> public
> contains T1;
> end;
T2 and T3 can't access a,b, even though they are exists for memory layout.
Mattias
More information about the fpc-devel
mailing list