VAR

VAR

Alternate syntax for VAR: instance variable for the objects.

Syntax

      VAR <DataName1> [, <DataNameN>] [ AS <type> ] [ INIT <uValue> ]
      [[EXPORTED | VISIBLE] | [PROTECTED] | [HIDDEN]] [READONLY | RO]

Arguments

<DataName1> Name of the VAR

<type> Optional data type specification from the following: Character, Numeric, Date, Logical, Codeblock, Nil.

<uValue> Optional initial value when creating a new object.

EXPORTED Specifies that this VAR is accessible to functions and methods outside of the class. VISIBLE is a synonym for EXPORTED.

PROTECTED Specifies that this VAR is only accessible to functions and methods within this class and its subclasses.

HIDDEN Specifies that this VAR is only accessible to the class where it was defined, and is not inherited by the subclasses.

READONLY Restricts assignment to the variable. If specified with the EXPORTED clause, assignment is only permitted from the current class and its subclasses. If specified with the PROTECTED clause, assignment is only permitted from the current class. RO is a synonym for READONLY.

Description

VAR elements can also be thought of as the “properties” of an object. They can be of any data type, including codeblock. Once an object has been created, the VAR elements are referenced with the colon (:) as in MyObject:Heading := “Last name”. Usually a class also defines methods to manipulate the VAR.

You can use the “AS <type>” clause to enforce that the VAR is maintained as a certain type. Otherwise it will take on the type of whatever value is first assigned to it.

Use the “INIT <uValue>” clause to initialize that VAR to <uValue> whenever a new object is created.

VAR can be a synonym for VAR, or it can use a slightly different syntax for compatibility with other dialects.

Examples

      CREATE CLASS TBColumn

         VAR Block      // Code block to retrieve data for the column
         VAR Cargo      // User-definable variable
         VAR ColorBlock // Code block that determines color of data items
         VAR ColSep     // Column separator character
         VAR DefColor   // Array of numeric indexes into the color table
         VAR Footing    // Column footing
         VAR FootSep    // Footing separator character
         VAR Heading    // Column heading
         VAR HeadSep    // Heading separator character
         VAR Width      // Column display width
         VAR ColPos     // Temporary column position on screen

         METHOD New()   // Constructor

      ENDCLASS

Compliance

Harbour

Platforms

All

Seealso

Object Oriented Programming, CLASS, METHOD, CLASS VAR, VAR

Advertisements

3 responses to “VAR

  1. Pingback: Harbour Statements | Viva Clipper !

  2. Pingback: Harbour Commands | Viva Clipper !

  3. Pingback: Harbour RG Summary | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s