Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2026-09

private visibility question

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

If I have the below TFoo, and in ANOTHER unit I declare var   foo: TFoo

then I can access
   foo.e := a1;

This works even though "a1" is private and not visible. But by being the type for a public field (or method) it becomes available.

This is not true for
   foo.b.abc;

Is that intentional?

unit Unit2;
{$mode ObjFPC}{$H+}
interface
uses   SysUtils;
type
   TFoo = class
   private type
     TEnum = (a1,a2);
     TBar = class
       protected
         procedure abc; virtual ; abstract;
     end;
public
   b: TBar;
   e: TEnum;
end;
implementation
end.

Reply by email

Martin Frb
to Martin Frb

my fault...

the procedure needed to be public.

Martin Frb wrote 44 lines
If I have the below TFoo, and in ANOTHER unit I declare var   foo: TFoo then I can access   foo.e := a1; This works even though "a1" is private and not visible. But by being the type for a public field (or method) it becomes available. This is not true for   foo.b.abc; Is that intentional? unit Unit2; {$mode ObjFPC}{$H+} interface uses   SysUtils; type   TFoo = class   private type     TEnum = (a1,a2);     TBar = class       protected         procedure abc; virtual ; abstract;     end; public   b: TBar;   e: TEnum; end; implementation end. _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email