[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 VAR

 Synopsis

         Declare instance variable(s)

 Syntax

         VAR <variable name list>
              [CLASS <class> | TYPE <type>]
              [READONLY | RO | ASSIGN <assign>]

 Arguments

         <variable name list> is a list of names of one or more
         variable to be included in the class being defined.

         CLASS <class> specifies the name of the class which values
         assigned to the declared variable(s) must belong. Any attempt to
         assign values of a different class will result in a runtime error.
         Under the Class(y) 2.4 error system, a wrongClass message will
         be sent to the object which caused the error.

         TYPE <type> specifies the type of value which can be assigned
         to the variable(s) being declared. <type> can be any one of
         the following seven Clipper data types: Array, Block,
         Character, Date, Integer, Logical or Numeric.
         An Integer type restriction will only accept integer values,
         whereas Numeric accepts both integer and floating-point
         values. The types Character and Numeric can be abbreviated
         to Char and Num.

         READONLY or RO restricts assignment to the variable(s)
         being declared. If the the declared variable(s) are exported
         (declared after the EXPORT: command), assignment will only be
         permitted from the current class and its subclasses, ie.
         assignment will have protected visibility. If the variable(s) are
         protected, assignment will only be permitted in the current class,
         ie. assignment will be hidden. If the variable(s) are hidden, the
         READONLY clause has no effect.

         ASSIGN <assign> allows more control over the restriction of
         assignment than the READONLY clause. <assign> can be one
         of the following three values: HIDDEN, PROTECTED, or
         EXPORTED. The value specified will determine the visibility of
         assignment to the variable(s) being declared.

 Description

         Includes the named variables, as instance variables, in the class
         being created. Each object (instance of a class) created contains
         its own copy of the instance variables of that class.

         The VAR command is usually used inside a class specification
         (CREATE CLASS...END CLASS block).

         If the optional READONLY clause (abbreviation RO) is
         included, Class(y) will prevent the variable from being assigned
         to, except in methods of that class. This has no meaning when used
         with variables declared hidden with the HIDDEN: command.

         If an assignment occurs which is illegal because a variable has
         been flagged as read-only, a Class(y) error will be generated. The
         error will take the form of a readOnlyErr message being sent
         to the object concerned.

 Examples

           CREATE CLASS Dialog
              VAR id
              VAR nTop, nLeft TYPE Numeric
              VAR oWin CLASS Window

           PROTECTED:
              VAR nCount READONLY
           EXPORT:
              VAR cTitle TYPE Char READONLY

              //...
           END CLASS

         In this class specification, the first VAR statement declares
         a variable named id. The next statement declares two variables,
         nTop and nLeft which are restricted to numeric values. Then a
         variable named oWin is declared, which is only permitted to refer
         to objects of class Window. After the PROTECTED: statement, a
         variable named nCount is declared as READONLY. Since the
         variable is protected, declaring it read-only prevents assignment
         to the variable outside the methods of the Dialog class. Finally,
         an exported variable named cTitle is declared, restricted to
         containing character data and, since it is exported but read-only,
         it is not assignable outside methods of the Dialog class or its
         subclasses.

 Note

         Instance variable names are only significant up to 9 characters,
         as opposed to Clipper's usual 10. See the section entitled
         Length of Variable Names.

 See Also

         CLASS VAR, Length of Variable Names


See Also: CLASS VAR Length of Variable Names
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson