TInvokeableVariantType.SetProperty does not allow to change the variant value
Original Reporter info from Mantis: abouchez
-
Reporter name: Arnaud Bouchez
Original Reporter info from Mantis: abouchez
- Reporter name: Arnaud Bouchez
Description:
In Delphi, custom variant late-binding allows to change the stored TVarData content, even if the parameter is passed as "const" to the overridden SetProperty method.
Setting values via late-binding for custom variant types does not allow to change the stored content under FPC, whereas it is possible in Delphi.
This is some kind of abuse of "const" on the Delphi side, since it should have been defined as "var". But it is needed to change the stored value, via late-binding.
TInvokeableVariantType.SetProperty() and DispInvoke() methods should use a "var" kind of parameter for the source TVarData.
This fix is mandatory for compatibility with Delphi, e.g. for using our Open Source libraries like mORMot, SynMongoDB, SynMustache and our JSON storage library.
Steps to reproduce:
Use the supplied SourceBug.dpr file to reproduce the issue.
It works as expected under Delphi, and fails under FPC.
Additional information:
IMHO fix consists in the following changes.
The CONST source parameter should be changed into VAR in the following lines:
- procedure fpc_dispinvoke_variant(dest : pvardata; VAR source : tvardata; calldesc : pcalldesc;params : pointer);compilerproc;
for the following files:
- compproc.inc
- variant.inc
- jcomproc.inc
- procedure DispInvoke(Dest: PVarData; VAR Source: TVarData; CallDesc: PCallDesc; Params: Pointer); override;
for the following files:
- tw17904.pas
- tw9162.pas
- variants.pp
- procedure sysdispinvoke(Dest : PVarData; VAR Source : TVarData;calldesc : pcalldesc;params : Pointer);cdecl;
for the following file:
- variants.pp
- dispinvoke: procedure(dest : pvardata; VAR source : tvardata;
calldesc : pcalldesc;params : pointer);cdecl;
for the following file:
- varianth.inc
- function SetProperty(VAR V: TVarData; const Name: string;
const Value: TVarData): Boolean;
for the following file:
- variants.pp
Mantis conversion info:
- Mantis ID: 26773
- Version: 2.7.1
- Fixed in version: 3.0.0
- Fixed in revision: 28997 (#34941fde)
- Monitored by: » luizamerico (Luiz Americo), » abouchez (Arnaud Bouchez)
- Target version: 3.0.0