TryVar2Single/TryVar2Dbl/TryVar2Ext/TryVar2Str raise instead of returning False
Brought to you by:
twm
In u_dzVariantUtils, TryVar2Single, TryVar2Dbl, TryVar2Ext and TryVar2Str catch the EVariantError of a variant that cannot be converted (e.g. the string 'abc' to Double, or a variant array to string) and raise EVariantConvertError instead of returning False. Their doc comments even say so ("@raises EVariantConvertError if there is some other conversion error").
TryVar2Int, TryVar2Int64, TryVar2LongWord and TryVar2Bool return False in the same case.
This also breaks the functions built on them:
Var2Dbl, Var2Ext, Var2DblStr and Var2Str promise to return the default (or NullValue) if the variant cannot be converted, but raise.TryVar2Number in u_dzNullableTypesUtils, so the AssignVariant of a nullable Single/Double/Extended raises where a nullable Int32/Int64 becomes Null.Fix: return False, like the integer and Boolean siblings. Callers that want the exception have Var2DblEx, Var2ExtEx and Var2StrEx.
Not a bug, the exception is intended:
TryVar2Xxxreturns False only for a Null or Empty variant, a variant that holds something that cannot be converted raisesEVariantConvertError. The comment above the conversion functions has said so since the initial import.The functions that deviate are
TryVar2Int,TryVar2Int64,TryVar2LongWordandTryVar2Bool, which return False in that case. That is [#63].Related
Bug Reports:
#63