The numeric TryVar2Xxx functions in u_dzVariantUtils convert with a plain assignment (_Value := _v) and only catch EVariantError. For a number outside the target type's range the RTL does not raise that, so with ehNoException they neither return False nor stay silent:
ehNoException |
Delphi 2007 Win32 | Delphi 12 Win32 |
|---|---|---|
TryVar2Int64(1e300), also -1e300, NaN, 1e19 |
raises EInvalidOp |
True, -9223372036854775808 |
TryVar2LongWord(1e300), also -1e300, NaN, 1e19 |
raises EInvalidOp |
True, 0 |
TryVar2LongWord(5e9) |
True, 705032704 |
True, 705032704 |
TryVar2LongWord(-1) |
True, 4294967295 |
True, 4294967295 |
TryVar2Single(1e300) |
raises EOverflow |
True, INF |
TryVar2Int(1e300), also -1e300, NaN, 1e19 |
raises EInvalidOp |
False (correct) |
TryVar2Int(5e9) returns False on both, which is what all of them should do.
Delphi 12 masks floating point exceptions, so an invalid conversion there gives the indefinite integer or INF instead of an exception, the same cause as in [bugs:#73] for TryStr2Float. The LongWord wraparound for 5e9 and -1 does not depend on that and happens on both versions.
This carries over to the nullable types built on these functions, e.g. TNullableInt64.AssignVariant(1e300) gives a valid value of -9223372036854775808 on Delphi 12 and raises EInvalidOp on Delphi 2007.
Expected: False for a value outside the type's range with ehNoException, EVariantConvertError with ehRaiseException.
Measured with a console program calling each function with ehNoException and printing the result, the value or the exception class.