I think I may have mentioned that I hate Variants:

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 then
WriteLn('equal')
else
WriteLn('not equal');

Of course, it will output ... ?

Nothing, it will raise an Invalid Variant Operation error instead because the = operator apparently cannot handle Variant arrays (at least in Delphi 2007).

This is a bug that apparently has been in TDbf.Lookup since forever and nobody ever noticed.

Or did I do anything wrong here?

Did I mention that I hate Variants?
https://sourceforge.net/p/tdbf/code/HEAD/tree/trunk/src/dbf.pas#l2141

Comments

  1. You need to check with VarIsArray and then do your own comparison. The array can have multiple dimensions, different types and whatever so VarCompare does not easily handle that.

    You are welcome to take a look at SameValue from Spring.pas which does that.

    ReplyDelete
  2. Stefan Glienke I implemented my own function which only takes 1 dimension into account, but checks if the bounds are the same before actually comparing. The thing is that it took me forever to figure out what the problem was because the Var1=Var2 expression looks so innocous.

    ReplyDelete

Post a Comment