Class statement (LotusScript® Language)

Defines a class with its member variables and procedures.

Syntax

[ Public | Private ] Class className [ As baseClass ]

classBody

End Class

Elements

Public | Private

Optional. Public specifies that the class is visible outside the module where the class is defined, as long as this module is loaded. Private specifies that the class is visible only in this module.

A class is Private by default.

className

The name of the class.

baseClass

Optional. The name of another class from which this class is derived.

classBody

Declarations and definitions of class members. Class members can include member variables; member procedures (functions, subs, and properties); a constructor sub, named New; and a destructor sub, named Delete. Constants cannot be class members.

Usage

The Public keyword cannot be used in a product object script or %Include file in a product object script, except to declare class members. You must put such Public declarations in (Globals).

Rules for defining classes:

  • Define a class only in module scope. Do not define a class within a procedure or within another class.
  • Do not use the word Object as a class name.

Rules for declaring member variables:

  • Omit the Dim keyword from the variable declaration of member variables.
  • A separate declaration is required for each member variable. You can't declare two or more member variables in a single declaration using a comma-separated list.
  • You can use the Public or Private keywords for variable declarations. A member variable is private by default; it can be accessed only within the class.
  • Member variables cannot be declared Static.
  • A class can include an instance of itself as a member, but the variable declaration cannot include the New keyword. That is, the variable declaration cannot create an object of the class.
  • Do not use the following LotusScript® keywords as member variable names: Public, Private, Static, Sub, Function, Property, Get, Set, New, Delete, and Rem.

Rules for declaring member procedures:

  • You can use the keywords Public or Private for procedure declarations. A member procedure is Public by default; it can be accessed outside of the class.
  • Member procedures cannot be declared Static.
  • All LotusScript® keywords are legal as member procedure names. Use the names New and Delete only to name the class constructor and destructor subs, respectively.

Rules for referring to class members:

  • Refer to class members using the notation objName.memberName, where memberName identifies a class member defined in the class of the object reference variable objName.
  • You can use the keyword Me to refer to the object itself when you are inside a member procedure. In the example, Me.textColor refers to the value currently assigned to the textColor member of this instance of the class.
  • If you name a class member with a LotusScript® keyword, you must refer to the member within member subprograms using the Me keyword.
  • Derived class methods can override methods of the base class. The signature of the overriding member must match the signature of the overridden member. Within the procedure of a derived class, you refer to a base class member of the same name using the notation baseClassName..memberName.
  • Use the With statement to work with members of a specific class using the notation .memberName.

Rules for working with objects (class instances):

  • To create an object, use the New keyword in a Dim or Set statement for an object reference variable.
  • LotusScript® sets the initial value of an object reference variable to NOTHING. Use the Is operator to test an object reference variable for the NOTHING value.
  • Any Variant variable can take an object reference as its value. Use the IsObject function to test whether the contents of a Variant variable are an object reference.
  • Use the Delete statement to delete an object. LotusScript® sets the value of variables that refer to the object to NOTHING.

A class definition can include a definition for the constructor sub, named New. If the definition exists, LotusScript® calls this sub each time it creates an object of that class.

A class definition can include a definition for the destructor sub, named Delete. If the definition exists, LotusScript® calls this sub whenever it deletes an object of that class.

Example