Forum > General

Private visibility specifier for generic types acting like Public specifier.

(1/1)

finchley:
It seems that the private specifier for generic extended records, objects, or classes is not honored and the fields/methods can be accessed as if they were public.  I'm not saying I'm not doing something wrong but for non-generic extended records, objects, and classes anything marked as private is treated as such.  The only way to get the generic types to honor the private specifier is to mark it as strict private.  And I'm not seeing anything in Section 8 of the Reference Guide that states that you must do that.

If you want me to post the code I can do that but I've attached a demo of my findings instead (because I'm lazy).

ASerge:

--- Quote from: finchley on July 12, 2022, 04:59:44 pm ---It seems that the private specifier for generic extended records, objects, or classes is not honored and the fields/methods can be accessed as if they were public.

--- End quote ---
When you specialize a type, the class (record, object) code is generated at this point. I.e. it becomes part of the current unit and private properties are made available.

Thaddy:
Also note private in itself has unit scope, only strict private has class or record scope.
But indeed *before* specialization you can access those . After specialization you can not.
That is also in line what would be expected.

PascalDragon:
I'll have to check what Delphi does here, but it might indeed be that the compiler does not check against the correct unit here.

Navigation

[0] Message Index

Go to full version