Statement CLASS VAR Foundation

Declaration of class variables (variables of the class object)

Syntax
CLASS VAR <VarName,...> ;
      [SHARED] [READONLY] [ASSIGNMENT HIDDEN | PROTECTED | EXPORTED]
or
CLASS VAR <MessageName> [IS <VarName>] [IN <SuperClass>] ;
      [SHARED] [READONLY] [ASSIGNMENT HIDDEN | PROTECTED | EXPORTED]
Parameters
<VarName,...>
<VarName,...> is a comma separated list with the names of the member variables (class variables) for the class object. The name for a class variable follows the same convention as normal variable names. It must begin with an underscore or a letter and must contain alpha numeric characters. The first 255 characters are significant.
<MessageName>
<MessageName> designates the message which must be sent to a class object in order to access the class variables with the name <VarName>. This defines an alternative name for a class variable. <MessageName> is then used in the source code instead of <VarName>. The use of <MessageName> is generally used when several superclasses are available in the class hierarchy with class variables having the same name.
<VarName>
When the option IS is used, a list of variable names cannot be declared. In this case, only a single name <VarName> for a class variable is permitted in the statement CLASS VAR.
<SuperClass>
When multiple superclasses have the same class variable <VarName>it can be specified explicitly from which superclass a class variable is to be accessed when an object receives the message <MessageName>. Only class variables in a superclass that are visible (which are not declared in the superclass with the attribute HIDDEN:) can be referenced.
SHARED
The option SHARED causes the value or contents of a class variable to be available in future subclasses. Without this option each subclass receives their own class variables with the name <VarName> or <MessageName> and access their own values. The value of a SHARED class variable exists only once for the declared class and all its subclasses. The options SHARED and ASSIGNMENT HIDDEN are mutually exclusive, since SHARED releases a class variable for the common use of subclasses, but ASSIGNMENT HIDDEN limits the assignment right to the current object class.
READONLY
The option READONLY limits data assignment for a class variable. The assignment of a value to a READONLY class variable is permitted within the methods of the class. If the class variable has global visibility (visibility attribute EXPORTED:), assignments can be made within methods of the class and its subclasses. With the visibility attribute PROTECTED:, READONLY limits the assignment to only the methods of the declared class.
ASSIGNMENT
The option ASSIGNMENT allows write access for a class variable to be defined independent of its visibility. When the write access is defined as HIDDEN, assigning values to the variable is permitted only within the methods of the declared class. When the write access is PROTECTED, assignment to the variable is confined to the methods of the declared class and its subclasses. With EXPORTED assignemt is also allowed outside of the source code of methods. EXPORTED is the default setting.
Description

The declaration CLASS VAR is used within the class declaration (between the CLASS...ENDCLASS statements). It declares a member variable as a class variable. A class variable is a member variable of the class object and it exists only once per class. Its value is the same for all instances of the class. When an instance of the class (an object) receives the message for a class variable, it forwards the message on to a class object.

With <MessageName> the message (or name) used for accessing a class variable can be changed. It defines an alternative name for a class variable. If a <MessageName> is defined, the variable <VarName> can only be accessed using <MessageName>.

<MessageName> can be defined when a class variable exists only in one of the superclasses to the class incorporating <MessageName>. When two or more superclasses exist which have the same names for class variables it is recommended that alternative names be declared for accessing class variables in each superclass. In this case the declaration is used in the form CLASS VAR..IS..IN.

The visibility of a class variable is determined by the visibility attribute set with one of the keywords EXPORTED:, PROTECTED: or HIDDEN: (see the section on each visibility attribute for more information). Write access that is specified by the options READONLY or ASSIGNMENT is not dependent on the visibility of a class variable. The following table contains the meaningful combinations between visibility attributes and data assignment:

Visibility and assignment

If a class variable is declared with the option SHARED, the value or contents of this class variable is also used in future subclasses. In this case, the class variable exists only in the declared class and its contents are accessable by all future subclasses (the value is the same). Without the option SHARED, each subclass receives its own copy of the class variable and accesses its own value for the class variable (see declaration CLASS).

Examples
CLASS VAR implementation
// The example illustrates the procedure for the initialization 
// of class variables. The class method :initClass() is 
// first declared and then programmed. 

CLASS Window 
   CLASS VAR Stack 
   CLASS METHOD initClass          // Declares class method 

   EXPORTED: 
   VAR    nTop, nLeft, nBottom, nRight 
   METHOD Hide, Show, Move, Resize, Close 
ENDCLASS 

CLASS METHOD Window:initClass      // Code for class method 
   ::Stack := {}                   // Initializes 
RETURN self                        // class variables 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.