Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2021-05

mantis 0038496 custom variants and documentation

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marco van de Voort

Before the 3.2.2 release I looked into mantis 0038496 and now I come back to it.

I noticed that custom variants are completely undocumented, is this know (IOW should I file a bug?). What I wanted to look up are the rules for implementing binaryop, since that is where the problem is.

The bug is for the following code:

{$ifdef fpc}
  {$mode delphi}
{$else}
  {$apptype console}
{$endif}
uses variants,fmtbcd;
var
   fBCD1: TBcd;
   V1, V2, V3:Variant;
   L1: Integer;
begin
   L1:=123;
   fBCD1:=1234.345;
   V1:=123;
   V2:=VarFmtBCDCreate(fBCD1);
   V3:=V1 + V2;
   writeln(v3);
   readln;
end.

The addition finally ends up in  TFMTBcdFactory.BinaryOp which is declared as follows

procedure TFMTBcdFactory.BinaryOp(var Left: TVarData; const Right:
TVarData; const Operation: TVarOp);

i.e.  not a 3 operand action, but a two operand.  This probably means that in the case of v3:=v1+v2 this is encoded as v1:=v1,v2,add, modifying V1.

The fmtbcd binaryop code however says that the left type (integer)  is not either double or a a FMTBCD custom variant and thus throws an exception.

I think it is allowed to change the result type of the variant passed in binaryop(), but am not 100% sure, and also not sure if there are other things to keep an eye for (e.g. finalization of the existing value).

Does anybody know open source custom variant examples other than fmtbcd ?

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 5 lines
Before the 3.2.2 release I looked into mantis 0038496 and now I come back to it. I noticed that custom variants are completely undocumented, is this know (IOW should I file a bug?).

Please do. I am aware of this issue, but it always falls between the other issues. If you happen to have some sample programs (however small) I can use to document this, please attach them to the issue.

I know that Synopse makes heavy use of the customvariant (I believe their JSON document it a customvariant), maybe it can be a source of inspiration.

Michael.

Reply by email

Don Alfredo
to Michael Van Canneyt

https://synopse.info/forum/viewtopic.php?id=5894

Op zo 30 mei 2021 10:44 schreef Michael Van Canneyt via fpc-devel <

Show quoted text 24 lines
: On Sun, 30 May 2021, Marco van de Voort via fpc-devel wrote: > Before the 3.2.2 release I looked into mantis 0038496 and now I come > back to it. > > I noticed that custom variants are completely undocumented, is this know > (IOW should I file a bug?). Please do. I am aware of this issue, but it always falls between the other issues. If you happen to have some sample programs (however small) I can use to document this, please attach them to the issue. I know that Synopse makes heavy use of the customvariant (I believe their JSON document it a customvariant), maybe it can be a source of inspiration. Michael. _______________________________________________ fpc-devel maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Ondrej Kelle
to Don Alfredo

chakracore-delphi (experimental/variants branch) also has a custom variant (descendant of TInvokeableVariantType) to wrap javascript values/objects so you can access properties and call methods on javascript objects at runtime (similar to how you can use ActiveX/Automation objects through Variants when not compiling against a type library).

https://github.com/tondrej/chakracore-delphi
Blog post:
https://tondrej.blogspot.com/2020/10/variant-support-in-chakracore-delphi.html

Cheers,
Ondrej

On Sun, 30 May 2021 at 11:39, Don Alfredo via fpc-devel <

Show quoted text 35 lines
wrote: https://synopse.info/forum/viewtopic.php?id=5894 Op zo 30 mei 2021 10:44 schreef Michael Van Canneyt via fpc-devel < >: > > > On Sun, 30 May 2021, Marco van de Voort via fpc-devel wrote: > > > Before the 3.2.2 release I looked into mantis 0038496 and now I come > > back to it. > > > > I noticed that custom variants are completely undocumented, is this > know > > (IOW should I file a bug?). > > Please do. I am aware of this issue, but it always falls between the other > issues. If you happen to have some sample programs (however small) I can > use to document this, please attach them to the issue. > > I know that Synopse makes heavy use of the customvariant (I believe their > JSON document it a customvariant), maybe it can be a source of > inspiration. > > Michael. > _______________________________________________ > fpc-devel maillist - > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Sven Barth
to Marco van de Voort: Before the 3.2.2 release I looked into mantis 0038496 and now I come back to it. I…
Marco van de Voort wrote 51 lines
Before the 3.2.2 release I looked into mantis 0038496 and now I come back to it. I noticed that custom variants are completely undocumented, is this know (IOW should I file a bug?). What I wanted to look up are the rules for implementing binaryop, since that is where the problem is. The bug is for the following code: {$ifdef fpc}  {$mode delphi} {$else}  {$apptype console} {$endif} uses variants,fmtbcd; var   fBCD1: TBcd;   V1, V2, V3:Variant;   L1: Integer; begin   L1:=123;   fBCD1:=1234.345;   V1:=123;   V2:=VarFmtBCDCreate(fBCD1);   V3:=V1 + V2;   writeln(v3);   readln; end. The addition finally ends up in  TFMTBcdFactory.BinaryOp which is declared as follows procedure TFMTBcdFactory.BinaryOp(var Left: TVarData; const Right: TVarData; const Operation: TVarOp); i.e.  not a 3 operand action, but a two operand.  This probably means that in the case of v3:=v1+v2 this is encoded as v1:=v1,v2,add, modifying V1. The fmtbcd binaryop code however says that the left type (integer)  is not either double or a a FMTBCD custom variant and thus throws an exception. I think it is allowed to change the result type of the variant passed in binaryop(), but am not 100% sure, and also not sure if there are other things to keep an eye for (e.g. finalization of the existing value). Does anybody know open source custom variant examples other than fmtbcd ?

The only one I'm aware of that makes use of BinaryOp is Python4Delphi ( https://github.com/pyscripter/python4delphi/blob/master/Source/VarPyth.pas ). mORMot derives its TSynInvokeableVariantType and thus its TDocVariant from TInvokableVariantType, but does not override the operator methods.

Regards,
Sven

Reply by email

Sven Barth
to Don Alfredo: https://synopse.info/forum/viewtopic.php?id=5894 Op zo 30 mei 2021 10:44 schreef Michael…
Don Alfredo wrote

I'm already working on a fix for this, cause I had seen that thread a few days ago already. It would have been nice however if you had found this out during the RC phase which had lasted long enough.

Also why is looking through the code of TSynInvokeableVariantType the first time I hear about the swapped order of parameters? Did you report this as a bug? And if not, why not? This could have been fixed with 3.2.2 as well! (And I'm indeed working on fixing it)

Also: no top posting, please.

Regards,
Sven

Reply by email

Marco van de Voort
to Sven Barth: The only one I'm aware of that makes use of BinaryOp is Python4Delphi (…

Op 2021-05-30 om 13:02 schreef Sven Barth via fpc-devel:

Show quoted text 17 lines
> > I think it is allowed to change the result type of the variant passed > in binaryop(), but am not 100% sure, and also not sure if there are > other things to keep an eye for (e.g. finalization of the existing > value). > > Does anybody know open source custom variant examples other than > fmtbcd ? The only one I'm aware of that makes use of BinaryOp is Python4Delphi ( https://github.com/pyscripter/python4delphi/blob/master/Source/VarPyth.pas ). mORMot derives its TSynInvokeableVariantType and thus its TDocVariant from TInvokableVariantType, but does not override the operator methods.

I think I saw this one before in March. I also remember the conclusion: this should be fixed in LefPromotion(), but FPC doesn't implement calling that method :-)

Reply by email