Variants are always fun, eh?
I am working on a legacy application that was last in D2007 to migrate it to Delphi XE.
Variants have changed quite a bit in the interim.
This line of code:
if (VarType(Value) = varString) and (Value = '') then
Exit;
returned True and exited in D2007, but doesn't in Delphi XE.
I have changed it to this:
if VarIsStr(Value) and (VarToStr(Value) = '') then
Exit;
I'm not convinced this is the "best" way to go. The Variants unit doesn't have a specific call to do this, and I certainly recall this being an issue for folks in the past. However, a search revealed no library function or any other accepted way.
Is there a "correct" or better way?
Best Answer
VarIsStr
is a perfectly plausible way to do it. This is implemented as:The change you are seeing is, of course, really due to the Unicode changes in D2009 rather than changes to variants. Your string will be
varUString
, akaUnicodeString
. Of course,VarIsStr
also picks upAnsiString/varString
andWideString/BSTR/varOleStr
.If you want a truly faithful conversion of your Delphi 2007 code then you would write:
Exactly what you need to do, only you can know, but the key thing is that you have to account for the newly arrived
varUString
.