8.3 Variant Handling

A Function Library is a component that contains a set of routines defined using the MthRoutine command. These function library routines can be used in expressions. To handle objects of type *VARIANT, you need to use the variant function library #PRIM_LIBV. (For string, number, date and time, using Intrinsic Functions is simpler than using a function library.)

Variants can contain any type of data (strings, integers, decimals, booleans, components). You can use variant functions for testing the kind of value contained in the variable and you can retrieve its value in converted forms like numbers, strings or booleans.

Variants make possible the generic processing of values regardless of their type. For example, the value of a grid cell cannot be known by the compiler before the application is executed. Therefore the Value parameter of grid EditorChanged and ItemChangedAccept events returns the value in the cell as a variant so that compiler errors about the declared type of the value do not occur. You then need to write the program in a way that understands what type(s) are in the grid.

Also the EditorChanged and ItemChangedAccept events of tree and list views return the Value parameter as a variant. Similarly, many ActiveX controls return and accept values as variants. You can also use variants in your own dynamic programs for generic processing of values regardless of their type. For example:

Define_Com Class(*VARIANT) Name(#lclVariant)

Using the *VARIANT class is the recommended approach. Alternatively, you can use primitive variant component #PRIM_VAR and its properties and methods.

#PRIM_LIBV supports these functions:

8.3.1 VarAsBoolean

8.3.8 VarIsNull

8.3.2 VarAsDecimal

8.3.9 VarIsNullReference

8.3.3 VarAsInteger

8.3.10 VarIsNumber

8.3.4 VarAsReference

8.3.11 VarIsReference

8.3.5 VarAsString

8.3.12 VarIsString

8.3.6 VarIsBoolean

8.3.13 VarType

8.3.7 VarIsEmpty



Also See

8.2 Function Libraries

Intrinsic Functions