Access modifiers restrict the visibility of program elements:
•PUBLIC/EXPORT: A public function, global, type (class, structure, delegate etc) or type member (field, method, property, event etc) is visible to all code within the same assembly (exe or dll) where it is declared and assemblies referenced by the declaring assembly. This is the default in X#.
•PROTECT/PROTECTED: The PROTECT(ED) keyword can be applied only to type members and restrict their visibility to code within the same type and classes that inherit from that type
•INSTANCE: A unique modifier keyword to X# (and Visual Objects), very similar to PROTECT, but applies only to class fields and has different semantics to PROTECT, on the way it is used by code within the same class (see sample below).
•PRIVATE/HIDDEN: Also applies to type members and is more restrictive than PROTECT, as it limits the member visibility to only code within the type where it is declared (not to classes inheriting from that type). If you declare a field or method as PRIVATE then the compiler may produce a compiler warning xs0169 when it detects that that field or method is never called inside the class.
•INTERNAL: Restricts the visibility of a type or member only to code from the same assembly (dll or exe). An internal member is not visible to any code outside the defining assembly, not even to classes inheriting from this class declared in other assemblies. Can be combined with PROTECTED, so that an INTERNAL PROTECTED member can be seen only from within the same class and also from inheriting classes that are defined in the same assembly, but not from inheriting classes that are defined in other assemblies.
•The XBase++ dialect also has the modifier STATIC, which means that the class is only visible in the source file where it is used.
Note: It is still possible to explicitly specify certain assemblies where internal types and members of an assembly are visible, by using the InternalsVisibleTo attribute. See documentation for System.Runtime.CompilerServices.InternalsVisibleToAttribute for more information.
INTERNAL PROCEDURE InternalProc() // procedure accessible only from within the same assembly
INTERNAL GLOBAL InternalGlobal AS INT // global accessible only from within the same assembly
PUBLIC CLASS TestClass // accessible from everywhere
EXPORT Export_field AS INT // accessible from everywhere
PROTECT Protected_field AS INT // accessible to this class and classes inherited from it
INTERNAL PROTECT Internal_Protected_field AS INT // accessible to this class and classes inherited from it, defined in this same assembly only
PRIVATE METHOD Private_Method() AS VOID // accessible only from code inside this particular class
END CLASS
A compatibility feature for code derived from Visual Objects, INSTANCE applies to fields and is similar to PROTECT, but has different semantics when a property (or ACCESS) is defined with the same name. When a PROTECT field is used and an ACCESS/ASSIGN pair (or PROPERTY) is defined with the same name in the type, then any code within that class that tries to access this member, always refers to the field. But when the member is declared with the INSTANCE keyword, the compiler binds the name to the ACCESS instead:
FUNCTION Start() AS VOID
TestClass{}:DoTest()
CLASS TestClass
PROTECT Protected_member := "field" AS STRING
INSTANCE Instance_member := "field" AS STRING
ACCESS Protected_member AS STRING
RETURN "access"
ACCESS Instance_member AS STRING
RETURN "access"
METHOD DoTest() AS VOID
? SELF:Protected_member // field
? SELF:Instance_member // access, because the field is defined with the INSTANCE keyword
END CLASS
This feature is a leftover from old Visual Objects versions that were emitting INSTANCE members for every control in the Window Editor and is depreciated in X#, but still available for compatibility reasons.