Class
Defines a class. Classes are templates from which objects are created — classes are object types, as opposed to value types. Objects are held by reference and are reference-counted. The memory an object occupies is freed when there are no more references to it — when no variables in the process refer to them.
Syntax:
[ attributes ]
[ Public | Private ] Class name [ ( Of typevars ) ]
[ Inherits baseclass ]
[ classmember ]
[ classmember ] …
End Class
- attributes
- optional One or more of:
ArrayBoundsChecks, ClassId, COMCreatable, CustomControl, Description, FloatingPointErrorChecks, FormDesignerId, Hidden, IntegerOverflowChecks, PredeclaredID - Public
- optional (twinBASIC) In an ActiveX project, marks the class as exported into the type library so that consumers in other projects can create and use it.
- Private
- optional (twinBASIC) In an ActiveX project, withholds the class from the type library: it remains usable within the project but is not exported. The conventional pairing with CoClass — a public CoClass as the consumer-visible contract paired with a
Private Classas the hidden implementation — relies on this modifier. - name
- The identifier naming the class.
- Of typevars
- optional (twinBASIC) One or more type variable names, separated by commas, that make the class a generic class. Each type variable can be referenced in member declarations as if it were a regular type. See Generics.
- Inherits baseclass
- optional (twinBASIC) Names a single base class whose Public and Protected members are inherited by name. The Inherits line, when present, must appear immediately after the Class header and before any other member. Inherits enables Overridable / Overrides members, explicit
*baseclass*.New(...)chained constructor calls from insideSub New, and Protected member visibility. See Inheritance. - classmember
- optional Any of the following:
- constant defined using Const,
- variable defined using Public, Protected, Private, or Dim,
- procedure defined using Sub, Function, or Property — including the special instance constructor
Sub New(args), which the runtime invokes when the class is created with New, - user-defined type (UDTs) defined using Type,
- (twinBASIC) Implements clauses, listing interfaces or classes whose members this class provides bodies for.
In .twin files, a Class block may share a file with Interface, CoClass, and Alias declarations (which appear before the Class block) and with a Module block. In legacy .cls files the class is implicit and the Class/End Class keywords are not written.