CLASS |
|
|
The CLASS statement declares a class module.
Format
CLASS name {MAX.ARGS limit} {INHERITS class.list}
where
QMBasic programs should commence with a PROGRAM, SUBROUTINE, FUNCTION or CLASS statement. If none of these is present, the compiler behaves as though a PROGRAM statement had been used with name as the name of the source record.
The CLASS statement must appear before any executable statements. For more details, see Object Oriented Programming.
The name need not be related to the name of the source record though it is recommended that they are the same as this eases program maintenance. The name must comply with the QMBasic name format rules.
A class module contains the components of a QMBasic object. The general structure of this is
CLASS name PUBLIC A, B(3), C PRIVATE X, Y, Z
PUBLIC SUBROUTINE SUB1(ARG1, ARG2) {VAR.ARGS} ...processing... END
PUBLIC FUNCTION FUNC1(ARG1, ARG2) {VAR.ARGS} ...processing... RETURN RESULT END
...Other QMBasic subroutines... END
The MAX.ARGS option can be used to increase the default limit on the number of arguments permitted in a public function or subroutine within the class module. This has a small effect on performance and should only be used where the default value of 32 needs to be exceeded.
The INHERITS option causes the named class or classes to be inherited automatically by this class when it is instantiated. Each name in the list can optionally be followed by initialisation values that will be passed to the CREATE.OBJECT subroutine of the inherited class. These values must be numeric or string constants. For example, CLASS MYCLASS INHERITS OTHERCLASS("RATE", 25) which is equivalent to use of OTHERCLASS = OBJECT("OTHERCLASS", "RATE", 25) INHERIT OTHERCLASS
If the inherited class is globally catalogued with a prefix character, the prefix is dropped when forming the object variable name. For example, CLASS MYCLASS INHERITS *OTHERCLASS creates an object variable named OTHERCLASS that references the inherited *OTHERCLASS object.
Alternatively, the name of the object variable can be set explicitly using the AS qualifier. For example, CLASS MYCLASS INHERITS *OTHERCLASS AS MYOTHERCLASS(1) Note that the initialisation values, if present, appear after the object variable name, not the catalogue name.
The second form shown above with explicit use of the OBJECT() function and the INHERIT statement allows the initialisation values to be expressions.
See also: Object oriented programming, DISINHERIT, INHERIT, OBJECT(), OBJINFO(), PRIVATE, PUBLIC. |