VarCast fails on Custom Variants
Original Reporter info from Mantis: pyscripter
-
Reporter name: Kiriakos
Original Reporter info from Mantis: pyscripter
- Reporter name: Kiriakos
Description:
Var
MyV, V : Variants;
begin
//Set My to a custom variant that implements Cast and CastTo and knows how
// to convert itself to an integer
VarCast(V1, MyV, varinteger); // <-- raises an exception (Type Mismatch)
The reason is that VariantToLongInt (and all similar routines) in cvarutil.inc do not take account of custom variants. If you look at the implementation of the corresponding function in Delphi _VarToInteger if the simple conversion fails, it calls VarToIntCustom that then calls the CastTo function of the custom variant. Delphi implements a series of VarToXXXCustom that handle simple type conversions.
This issue reduces drastically the usability of Custom Variants, since you cannot convert their values to simple types.
The same issue also exists in FPC 2.5.1.
Mantis conversion info:
- Mantis ID: 20849
- Version: 2.4.4
- Fixed in version: 3.3.1
- Fixed in revision: 48477 (#fe5b29c1)
- Monitored by: » alexvins (Alexander Shishkin)