Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

8.1.3 Variant Variable

You can use the Variant component class #PRIM_VAR to create a variant component variable. A variant component variable can contain any type of data (strings, integers, decimals, booleans, components).

...

This statement defines a variant variable called #MYVARIANT:

     Define_Com Class(#PRIM_VAR) Name(#MYVARIANT)

You can assign a value to the variant variable either using its Value property (in which case the type of the value is of unspecific type):

     Set Com(#myvariant) Value(#XYZ)

Or by explicitly assigning its value type using the String, Integer, Boolean, Decimal or Component properties of the variable:

     Set Com(#myvariant) Integer(#XYZ) 

...

When you read the value of the variable it is automatically converted to the type of the field that receives the value:

     Set Com(#Out_INTEGER) Value(#myvariant)

Or you can also explicitly specify the type of value:

     Set Com(#Out_INTEGER) Value(#myvariant.Integer)

To ensure that the value in the variant is one that you can support you use the ValueType property of the variable.

     IF Cond('#myvariant.ValueType = VarInteger')
Set Com(#Out_INTEGER) Value(#myvariant)
ELSE
Set Com(#Out_INTEGER) Value(0)
ENDIF

If this check is not performed and the value cannot be converted at runtime, you will get a runtime error.

...