Why does the =
operator results True
when comparing a varEmpty
Variant
variable with a zero evalued varInteger
Variant
variable?
var
V1 : Variant;
V2 : Variant;
begin
V2 := 0;
if(V1 = V2)
then ShowMessage('V1 = V2')
else ShowMessage('V1 <> V2');
end;
This code produces the following output:
V1 = V2
Does the equality operator =
only checks the value part of Variant
variables?
In order to make a comparison, the empty variant is converted to an integer. According to the variant type conversion rules, the unassigned (empty) variant is converted to 0. Hence the expression returns true.