All operators except ^, is,
and in take variant operands. Operations on variants return Variant
values; they return Null if one or both operands is Null, and
raise an exception if one or both operands is Unassigned. In a binary
operation, if only one operand is a variant, the other is converted to a
variant.
The return type of an operation is determined by its operands. In general, the same rules that apply to operands of statically bound types apply to variants. For example, if V1 and V2 are variants that hold an integer and a real value, then V1 + V2 returns a real-valued variant. With variants, however, you can perform binary operations on combinations of values that would not be allowed using statically typed expressions. When possible, the compiler converts mismatched variants using the rules summarized in Variant type conversions. For example, if V3 and V4 are variants that hold a numeric string and an integer, the expression V3 + V4 returns an integer-valued variant; the numeric string is converted to an integer before the operation is performed.
除了 ^、is 和 in 之外,所有的运算符都可以将变体作为操作数。作用于变体的运算返回标准变体类型Variant值;如果一个或两个操作数都是Null,那么运算结果返回Null,如果一个或两个操作数都是Unassigned,那么将引发异常。在二进制运算中,当切仅当一个操作数是变体时,另一个被转换为变体。
表达式返回值的类型取决于操作数。一般情况下,适用于静态范围类型操作数的规则也适用于变体。例如,如果V1和V2分别是保存了整数和实数值的变体,那么表达式V1 + V2将返回一个实数值格式的变体。然而,对于变体,可以执行二进制操作来合并值,而这样的操作对于静态类型表达式是不允许的。在可能的情况下,编译器使用变体类型转换中概述的规则转换不匹配的变体。例如,如果V3和V4分别是保存了数字串和整数的变体,那么表达式V3 + V4返回整数值格式的变体;这种情况下,在运算执行之前,数字串被转换为整数。