I hate Variants, did I say that before? They just make everything more complex than necessary.
I hate Variants, did I say that before? They just make everything more complex than necessary.
Did you ever try to compare two variants? E.g. you have got one that contains an empty string (”) and another that contains a date. Now you want to know whether they are equal or not. Simple?
if v1 <> v2 then
WriteLn('not equal')
else
WriteLn('equal');
Not so. The code above raised a EVariantConversionError exception because it could not convert an empty string into a date. ...
http://blog.dummzeuch.de/2014/07/01/comparing-variants/
Did you ever try to compare two variants? E.g. you have got one that contains an empty string (”) and another that contains a date. Now you want to know whether they are equal or not. Simple?
if v1 <> v2 then
WriteLn('not equal')
else
WriteLn('equal');
Not so. The code above raised a EVariantConversionError exception because it could not convert an empty string into a date. ...
http://blog.dummzeuch.de/2014/07/01/comparing-variants/
I'm not using Variants, but is VarSameValue or VarCompareValue is not what you need?
ReplyDeleteI should read the link first, then comment ..
VarSameValue will raise the exact same exception.
ReplyDeleteYou should write:
if v1 <> VarToStr(v2) then
Also the comparison itself might be just wrong because if v2 contains a date it will never equal to empty string (except when using VarToStr which returns an empty string when the variant is null). It rather might contain Null which you can check.
That's what I found out later and therefore changed the blog post.
ReplyDeleteMy code tries to find out whether a variant's value changes due to an assignment, so a database table record needs to be written or not. So all I want to know is whether the variants are exactly the same or not.
ReplyDelete(Did I mention that I hate Variants?)
Hate often is the result of misunderstandings ;)
ReplyDeletePoor misunderstood Variants, then?
ReplyDeleteI wonder whether the hate is mutual... ;-)
Using variants require care. It may be a date, it may be an OLE object.
ReplyDelete