Here in the Netherlands we have a saying that Cruyff once translated into English as " can't make any cheese of it", meaning what do you mean?
Anyway, all this is properly documented:
- A global - in whichever unit,
but subsequent used unit unit order is important- is visible to the whole program. This goes for everything declared in the interface section of a unit or the program source itself. Note that the program file itself has always access to any global declared in any used unit.
- A local - in whichever unit - is visible only to the unit in which it is declared and is declared in the implementation section of a unit. Or declared inside a method.
- A record has three possible visibilities for its members: strict private, private and public. strict private are members only visible to the record itself, private record members are only accessible from within the implementation section of the unit where it is declared or the record members themselves. Public is the default and means the record members are visible throughout the whole program, but again unit order is important.
- A class has strict private, strict protected, private, protected, public and published meaning:
strict private: accessible only for the class itself
strict protected: accessible only for the class itself and any derived classes
private: only accessible from the class itself, but can be referenced to in the implementation section of the unit where the class is declared. (really legacy or an historical oversight)
protected: only accessible from the class itself and derived classes, but also accessible from within the implementation unit where the class is declared (same historical oversight)
public: means visible and accessible anywhere in the program (but unit order applies).
published means the same as public, but in addition RTTI information is generated. (This is no longer 100% corrrect, a bit muddy). It is necessary for e.g. property editors and persistent storage in general.
Note that records can't have protected members, because there is no record inheritence so would not make sense.
From the point of view of language design
strict should never have been necessary, but it will break an awful lot of code if private and protected would be strict....(give programmers a shortcut and they WILL use it!! and that happened..)
Any visibility in general to other units needs to have a reference to that unit either in the implementation section or the interface section.
Most of this can be found in the manuals. This write up is close, but still not 100% correct, so expect border cases and knit picking....
from the Yesbut tribe. (you know, the folks from Outlandia)
mm, I should copyright that!Oh I forgot:
classes and records can also be declared in an implementation section: in that case their use is also restricted to the unit itself.