Use the CAST function
- Last Updated: May 29, 2019
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
You can thus use the CAST function wherever an object reference is permitted:
- To assign an object reference to an object reference data element, especially when assigning a super class or interface reference to a related subclass or interface-implementing class element, respectively.
- To pass a super class object reference as an argument to a routine
INPUTparameter defined as a subclass type, or to pass an interface object reference as an argument to a routineINPUTparameter defined as a class that implements the passed interface type. - To access a method, property, or data member on a subclass of a
specified class-type object reference, or on a class that implements a specified
interface-type object reference. You can do this by implicitly using the return value of
the
CASTfunction as the new object reference on which to access the method, property, or data member.
Syntax descriptions for each of these uses of the CAST function follow.
This is the syntax
for the CAST function when used to assign an object
reference to another object reference data element:
|
This is the syntax for the CAST
function when used to pass an object reference to an INPUT
parameter:
|
This is the syntax for the CAST
function when used to cast an object reference to access a method, property, or data
member:
|
Element descriptions for these syntax diagrams follow:
- target-object-reference
- A data element defined as the object reference type specified by
target-type-name, typically defined to reference
one of the following types:
- A subclass of the class whose type defines the object-reference
- A class that implements the interface whose type defines the object-reference
- object-reference
- An object reference source, whose type is typically defined as a super
class of target-type-name, or an interface
implemented by a class type specified by target-type-name. This can be a variable or it can be a temp-table field
defined as
Progress.Lang.Object.At run time, the AVM verifies that object-reference in fact points to an instance of the specified target-type-name. - target-type-name
- The type name of the target class or interface type for the cast. Any
class type name must specify one of the following types:
- The same class whose type defines object-reference
- A super class of the class whose type defines object-reference
- A subclass of the class whose type defines object-reference
- A class that implements the interface whose type defines object-reference
Any interface type name must specify one of the following types:
- The same interface whose type defines object-reference
- An interface implemented by the class type that defines object-reference
The specified type name can be a fully qualified object type name or an unqualified class or interface name, depending on the presence of an appropriate
USINGstatement in the class or procedure file. For more information on object type names, see Define and reference object type names. For more information on theUSINGstatement, see Reference an object type name without its package. - routine-name
- The name of any procedure, user-defined function, or method that takes
an object reference argument as
INPUT. The correspondingINPUTparameter defined by routine-name must have a data type that is compatible with target-type-name. - member-name [ ( ... ) ]
- This can be one of the following:
- The name of a
PUBLICmethod (and its parameter list) defined by the class or interface type specified by target-type-name. The compiler verifies that member-name specifies a valid method defined by target-type-name and that the parameters () are valid.(...) - The name of a
PUBLICdata member defined by the class type specified by target-type-name. The compiler verifies that member-name specifies a valid data member defined by target-type-name. - The name of an accessible
PUBLICproperty defined by the class type specified by target-type-name. The compiler verifies that member-name specifies a valid property defined by target-type-name, and that the specified property is accessible (readable or writable) in the coded context.
- The name of a