xHarbour Reference Documentation > Statement Reference |
|
|
VAR
Declares an instance variable of a class.
Syntax
VAR <MemberName> [ INIT <expression> ] ;
[ READONLY ] [ PERSISTENT ]
VAR <MessageName> IN <SuperClass>
VAR <MessageName> IS <MemberName> IN <SuperClass>
VAR <MessageName> TO <ContainedObject>
VAR <MessageName> IS <MemberName> TO <ContainedObject>
Arguments
- <MemberName>
- This is the symbolic name of the instance variable to declare. It must begin with
a letter or underscore followed by digits, letters or underscores. The symbolic
name can contain up to 63 characters.
- INIT <expression>
- This is the expression which is executed when an object is created. The return
value of <expression> is assigned to <MemberName>.
- READONLY
- This option declares an instance variable as read only. I.e. when the object exists
outside the declaring PRG module, no value can be assigned to <MemberName>. The
value of <MemberName> can be changed within methods of the class.
- PERSISTENT
- This option specifies that the value assigned to <MemberName> is persistent. When
an object is serialized with HB_Serialize() and later restored with
HB_Deserialize(), the value of <MemberName> is also restored. All
instance variables not declared as PERSISTENT are initialized with NIL when a
serialized object is restored from its character representation.
- <MessageName>
- This is the symbolic name of an alternative message to declare for the class.
- IN <SuperClass>
- Optionally, the name of the super class can be specified to which the message should
be sent. This requires the class to inherit one or more other classes.
- IS <MemberName>
- When a message should be directed to a super class, the member variable to access in the
super class can be specified with <MemberName>.
- TO <ContainedObject>
- This is the symbolic name of an instance variable holding the object that whose
instance variable is accessed.
Description
The VAR statement can only be used in the class declaration
between CLASS and ENDCLASS. It declares the symbolic name of an instance variable.
This name must be sent to an object to access the instance variable.
VAR is more versatile than the DATA declaration, since it allows
for declaring message delegation to contained objects or super classes. Refer
to DATA for more information on instance variable declaration.
Info
Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe