How to: |
Reference: |
Before you can declare an object (an instance of a class), your procedure must have a class definition for that type of object. If the class:
This procedure describes how to define a new class. If you wish to define a new subclass, that is, a class that inherits properties from another class, see How to Define a Subclass Using the Class Editor.
The Member Variable dialog box opens.
The name of each member variable must be unique within the class to which it belongs. It can be identical, however, to the names of member variables of other classes.
The Member Function dialog box opens.
The name of each member function must be unique within the class to which it belongs. It can be identical, however, to the names of member functions of other classes.
To define a new class (a subclass) by inheriting properties (member functions and member variables) from another class (a superclass):
The Member Variable dialog box opens.
Note: You cannot delete member variables inherited from the superclass.
Note that you cannot delete member functions inherited from the superclass. However, you can override an inherited member function it to edit or remove its source code.
The Member Function dialog box opens.
The name of each member function must be unique within the class to which it belongs. It can be identical, however, to the names of member functions of other classes.
When you define a class using the Class Editor, it generates the definition in the procedure as a DESCRIBE command. If you wish to work directly with source code, you can create new class definitions and edit existing definitions directly in the Procedure Editor by using the following DESCRIBE syntax. You must issue the DESCRIBE command outside of a function, for example, at the beginning of the procedure prior to all functions.
DESCRIBE classname = ([superclass +] memvar/type [, memvar/type] ...) [;] [memfunction [memfunction]... ENDDESCRIBE]
where:
Is the name of the class that you are defining. The name is subject to the standard naming rules of the Maintain Data language.
Is the name of the superclass from which you wish to derive this class. Include only if this definition is to define a subclass.
Names one of the member variables of the class. The name is subject to the Maintain Data language standard naming rules.
Is a data type (a built-in format or a class).
Defines one of the class member functions. Member functions are defined the same way as other Maintain Data functions, using the CASE command.
Terminates the definition if the definition omits member functions. If it includes member functions, the semicolon (;) is omitted and the ENDDESCRIBE command is required.
Ends the class definition if it includes member functions. If it omits member functions, the ENDDESCRIBE command must also be omitted, and the definition must be terminated with a semicolon (;).
To add a new member function or member variable:
To edit one of the member functions or member variables of a class:
If you wish, you can edit the Maintain Data code directly in the Procedure Editor.
The New Class and Edit Class dialog boxes enable you to create and edit classes. An example of the New Class dialog box is shown in the following image.
The New Class dialog box contains the following tabs:
General tab
The General tab has the following options:
Type the name of your class here.
If this class is based on another class, select that class from the list. The list comprises all of the classes that are defined in the open import module or procedure, and in any modules that have been imported into it.
Functions tab
The Functions tab includes the following options:
Lists the names of the member functions of a class.
Opens the Member Function dialog box, where you can define a new function.
Deletes a selected function from the list of functions, or if a function has been overridden, deletes the override.
Moves a selected function up in the list of functions.
Moves a selected function down in the list of functions.
Variables tab
The Variables tab includes the following options:
Lists the class member variables, including those that it has inherited.
Opens the Member Variable dialog box, where you can define a new variable.
Deletes a selected variable from the list of variables. You cannot delete variables that are inherited from another class definition.
Moves a selected variable up in the list of variables.
Moves a selected variable down in the list of variables.
Description tab
The Descriptions tab has the following elements:
You can document the class by typing a description of it in this edit box. Maintain Data will turn your description into a comment in the class definition source code in the procedure or module.