Cast

This function casts a generic instance to an instance of specific class or representation.

Syntax

SPECIFIC_INSTANCE=cast(GENERIC_INSTANCE, CLASS_NAME)

Example

# Generic Instance that we will cast laterLocal Instance OBJECT_INSTANCE Using OBJECT# Assign a C_ORDERLINE instance to OBJECT_INSTANCE# Note: we cannot invoke C_ORDERLINE methods on OBJECT_INSTANCE as it was declared# as an OBJECT instance rather than a C_ORDERLINE instance.OBJECT_INSTANCE = NewInstance With C_ORDERLINE# Declare an array of 15 C_ORDERLINE instancesLocal Instance SORDER_LINES(1..15) Using C_ORDERLINE# Assign OBJECT_INSTANCE to the first element of the array# A cast is necessary to obtain compatible types.SORDER_LINES(1) = cast(OBJECT_INSTANCE, "C_ORDERLINE")# Retrieve the objectType property of this array elementTYPE=SORDER_LINES(1).Objecttype# TYPE is "C_ORDERLINE"

Comments

OBJECT is a generic class for variables that may hold instances allocated in different classes.
The OBJECT class does not have any properties or methods, besides the built-in properties available on all objects.
You must cast an OBJECT variable with the appropriate class name to access its properties and methods,
or to assign it to a variable of a specific class.

See also

Structure, FreeInstance, Instance, NewInstance, SetInstance, allocgrp, null