For Variant types, the =
comparison operator in Delphi maps to the VarCompareValue
in the Variants
unit.
That function fails to handle various comparisons and for some it knows it can handle raises a VarInvalidOp
through various code paths (like CheckType
) to VarInvalidOp
because the implementation limits itself to varEmpty..varUInt64
, which I think means that these are unsupported:
varRecord
varStrArg
varObject
varUStrArg
varString
varAny
varUString
varArray
varByRef
This fails when using the =
operator:
What is this code supposed to do, if
v1
andv2
are variant arrays with the same content?if v1 = v2 then WriteLn('equal') else WriteLn('not equal');
Spring4d has a function SameValue
in the Spring.pas
unit which handles more cases, at least the case when both operands are arrays having the same content.
Source: [WayBack] I think I may have mentioned that I hate Variants: What is this code supposed to do, if v1 and v2 are variant arrays with the same content? if v1 = v2… – Thomas Mueller (dummzeuch) – Google+
Thanks to Thomas Mueller and Stefan Glienke for this.
–jeroen