Skip to content

VarSameValue raises exception when comparing arrays

Summary

According to the documentation of VarSameValue, "the actual values are compared" for all variant types except Null and Empty. However, comparing variant arrays raises an exception. The error is caused in variants.pp line 3096 where a simple "a=b" comparison is made.

I wanted to use VarSameValue just because I know that "a=b" can be problematic with variants. The VarSameValue function should handle this case correctly.

System Information

  • Operating system: Windows 8.1 Pro, 64 bit
  • Processor architecture: x86-64
  • Compiler version: 3.2.2
  • Device: Computer

Steps to reproduce

program Project1;

uses Variants;

var a, b: Variant;

begin
  a := VarArrayOf ([1, 2, 3]);
  b := VarArrayOf ([1, 2, 3]);
  Writeln (VarSameValue (a, b));
end.

What is the current bug behavior?

EVariantInvalidOpError: Invalid variant operation Array of Variant = Array of Variant

What is the expected (correct) behavior?

VarSameValue should correctly perform the comparison. Two arrays are equal if their dimensions are equal, their lengths are equal and all of their elements are equal. Comparing an array with a single value (e.g. [5]) with the same primitive value (e.g. 5) should imho return false, but one can discuss this case, of course.

Possible fixes

I will try to find and suggest a fix. If I succeed, I will update this bug report.

Edited by Tom
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information