SHARED |
|
|
The SHARED statement declares persistent variables to be shared across all instances of a QMBasic class module.
Format
SHARED {PRIVATE | PUBLIC} {var1 {,var2...}
where
The SHARED statement is used to define variables in class modules that are to be visible to all instances of the same class within a QM process. The variables are discarded when the last instance of the class is destroyed.
The variable names may extend over multiple lines by splitting the statement after a comma. For example
SHARED PUBLIC VAR1, VAR2, VAR3, VAR4
The same variables could be defined as
SHARED PUBLIC VAR1 SHARED PUBLIC VAR2 SHARED PUBLIC VAR3 SHARED PUBLIC VAR4
The compiler assumes that definitions of variables in each SHARED statement are a continuation of any previous definitions in the same class module.
Shared variables are initially unassigned and may be defined as either private or public. The SHARED statement does not support use of initialisation values. Where shared variables are to be initialised in the CREATE.OBJECT subroutine on creation of just the first instance of the class, this can be achieved by testing whether one shared variable is unassigned using a construct of the form IF UNASSIGNED(variable.name) THEN ...do initialisation... END
Shared variable definitions may include matrices. These are defined by including the row and column bounds in the SHARED statement, for example
SHARED MAT1(5,3)
QM supports two styles of matrix with different characteristics. The PICK.MATRIX setting of the $MODE compiler directive can be used to select Pick style matrices.
The default style of matrix includes a zero element and is resizeable. A shared variable list declared as SHARED A,B(3),C has three variables, one of which is a matrix:
A matrix of this type can be re-dimensioned by a later DIM statement.
Pick style matrices do not have a zero element and cannot be resized. A matrix of this type is equivalent to a series of simple variables:
See also: |