Declaring Objects

How to:

After a class definition exists, you can declare objects of that class. This is identical to declaring simple variables of a built-in data type. You can declare objects using the Class Editor, or by coding the declaration directly in the Procedure Editor.

Procedure: How to Declare an Object Using the Variable Editor

Prerequisite: When declaring an object (that is, a class instance), the procedure in which you are declaring it must already include or import the class definition.

To declare an object using the Variable Editor:

  1. Select the procedure in which you want the object to be declared.
  2. Right-click the procedure, click New in the shortcut menu, and click Variable (Declare) in the submenu.

    or

    Click the New variable button New variable button on the Application toolbar.

  3. In the New Variable dialog box, type a name for your object in the Name field.
  4. Open the Type drop-down combo box. If the class of which this object will be an instance:
    • Is listed in the Type combo box, select it, and skip to step 9.
    • Is not listed in the Type combo box, and you know its name, enter the name in the Type combo box and skip to step 9.
    • Is not listed in the Type combo box, and you wish to select it from a list of all the class procedures, click the ellipsis button ellipsis button to open the Type Wizard and continue with step 5.
  5. Select User-defined Class from the drop-down list.
  6. From the drop-down list select Simple for a single object, or Stack of for a list of objects.
  7. Select a class from the list.

    This adds the class to the list of data types in the Type combo box in the New Variable dialog box, making it available to you when you create additional objects in the future.

  8. Click OK to return to the New Variable dialog box.
  9. Optionally, click the Description tab and enter a description. This description will be generated as a comment with the object declaration's source code.
  10. Click OK to confirm the object declaration.
  11. The Variable Editor created a global object declaration. If you wish to convert this to a local object declaration, while in the Procedure Editor simply cut the declaration from the $$Declarations section at the top of the procedure, and paste the declaration to the desired function.

    Note that local declarations must immediately follow the function CASE command, preceding all the other commands in the function.

Syntax: How to Declare an Object Using the DECLARE Command

You can declare a local or global object in the Procedure Editor using the DECLARE command. To make the declaration:

  • Local, code the DECLARE command in the function to which you want it to be local, following the function CASE command, and preceding all the other commands in the function.
  • Global, code the DECLARE command outside of any function. It is recommended that you use the $$Declarations section at the top of the procedure to make the declaration easier for you to find.

    You can also create global objects using the COMPUTE command. For information about the COMPUTE command, see COMPUTE.

To declare an object in the Procedure Editor using the DECLARE command, use this syntax

DECLARE
[(]  
objectname/class;
.
.
.
[)]

where:

objectname

Is the name of the object that you are creating. The name is subject to the standard naming rules of the Maintain Data language.

class

Is the name of the class of which this object will be an instance.

( )

Groups a sequence of declarations into a single DECLARE command. The parentheses are required for groups of local declarations. Otherwise, they are optional.