Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming

> ## Defining an object reference as a field in a temp-table

> Temp-tables can define classes as fields. Classes are always represented by value, that is, the value of the object reference, not the object itself. You define a class field in a temp-table as a `Progress.Lang.Object`, the built-in class that is the implicit super class (root class) of all user-defined classes. When object instances are assigned to the field, they are implicitly cast to the root class, `Progress.Lang.Object`. When you want to use the object reference as a specific class type, you must cast the object reference to the specific type. For more information on casting, see the "Assignment and the CAST function" section.

> As with class type parameters, a temp-table containing a class field cannot be passed to or from a remote application server.

> This is the syntax to define a class field in a temp-table:

> Syntax
>     FIELD field-name AS [ CLASS ] Progress.Lang.Object

> Element descriptions for this syntax diagram follow:

> ``field-name``

> The name of a field defined as the Progress root class.

> Note: You cannot define a class field in an OpenEdge database table.

> The following example defines a temp-table field to hold a class instance, by defining the field as `Progress.Lang.Object`. In this case, the purpose is to store different `ShapeClass` instances in order to calculate an area on each `ShapeClass` object in sequence, according to its subclass type (`RectangleClass` or `CircleClass`), as shown:

>     CLASS Main:
>         DEFINE VARIABLE width AS DECIMAL NO-UNDO INITIAL 10.0.
>         DEFINE VARIABLE length AS DECIMAL NO-UNDO INITIAL 5.0.
>         DEFINE VARIABLE radius AS DECIMAL NO-UNDO INITIAL 100.0.
>         DEFINE TEMP-TABLE myTT NO-UNDO
>                 FIELD shapes AS CLASS Progress.Lang.Object
>                 FIELD area AS DECIMAL.
>         CONSTRUCTOR PUBLIC Main ( ):
>             CREATE myTT.
>             myTT.shapes = NEW RectangleClass (INPUT width, INPUT length).
>             CREATE myTT.
>             myTT.shapes = NEW CircleClass (input radius).
>             FOR EACH myTT:
>                 /* Cast field to common super class ShapeClass */
>                     myTT.area =
>                         CAST(myTT.shapes, "ShapeClass"):CalculateArea ( ).
>                 MESSAGE myTT.area VIEW-AS ALERT-BOX.
>             END.
>         END CONSTRUCTOR.
>     END CLASS.

> The previous example is based on the classes used to demonstrate polymorphism in a previous chapter (see the "Using polymorphism with classes" section). This version of the `Main` class thus shows how you might use temp-table fields to support polymorphic object references and use the `CAST` function to cast down to the common functionality of the polymorphic super class (`ShapeClass`).

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095