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.


Top of page

x
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 procedure's classes, click the ellipsis button ellipsis button to open the Type Wizard and continue with step 5. For more information, see Using the Type Wizard.
  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's CASE command, preceding all the other commands in the function.


Top of page

x
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:

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 language. For more information, see Specifying Names in Language Rules Reference in the Maintain Language Reference manual.

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.


WebFOCUS