Release 10.1A: OpenEdge Development:
Progress 4GL Reference

> ## CAST function

> Casts an object reference of one class type to another class type within a class hierarchy.

> When you cast an object reference, Progress treats the object reference as if it were an instance of the class type to which it was cast. The underlying object instance does not change.

> #### Syntax

>     CAST( object-reference, type-name ).

> ``object-reference``

> An object reference for the user-defined class object instance to cast.

> ``type-name``

> A character string that specifies the type name of the class or interface to which the object reference is cast. This class or interface must be in the hierarchy of the defined class. Specify a type name using the `package`.`class-name` syntax as described in the Type-name syntax reference entry in this book.

> #### Notes

> - You typically cast an object reference down a class hierarchy (that is, from a super class to a subclass within a class hierarchy). Since a subclass contains all the super classes in its inherited class hierarchy, Progress can implicitly cast an object reference up a class hierarchy.

> - At compile time, Progress verifies that the specified class type is within the class hierarchy of the specified object reference. At run time, Progress checks the validity of the cast operation.

> - You can use the CAST function to cast an object reference to a subclass and invoke a method defined in that subclass using the following syntax:

>     CAST( object-reference, type-name ):method-name( ).

> You can also use the CAST function to cast a parameter in a parameter list for a method using the following syntax:

>     method-name( INPUT CAST( object-reference, subclass-name ), ... ).

> You can also use the CAST function to cast a temp-table field, which is defined as a Progress.Lang.Object, to use as an object of another class type. For example:

>     DEFINE TEMP-TABLE mytt FIELD CustObj AS Progress.Lang.Object.
>     DEFINE VARIABLE RCustObj AS CLASS acme.myObjs.CustObj.
>     RCustObj = CAST(mytt.CustObj, "acme.myObjs.CustObj").

> You can now use the object reference in`` RCustObj to invoke methods in the `acme.`myObjs.`CustObj` class.

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