Re: [fpc-devel] mantis 0038496 custom variants and documentation

2021-05-30 Thread Marco van de Voort via fpc-devel


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




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 :-)

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] mantis 0038496 custom variants and documentation

2021-05-30 Thread Sven Barth via fpc-devel

Am 30.05.2021 um 11:39 schrieb Don Alfredo via fpc-devel:
https://synopse.info/forum/viewtopic.php?id=5894 



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
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] mantis 0038496 custom variants and documentation

2021-05-30 Thread Sven Barth via fpc-devel

Am 30.05.2021 um 00:53 schrieb Marco van de Voort via fpc-devel:
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
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] mantis 0038496 custom variants and documentation

2021-05-30 Thread Ondrej Kelle via fpc-devel
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 <
fpc-devel@lists.freepascal.org> wrote:

> https://synopse.info/forum/viewtopic.php?id=5894
>
> Op zo 30 mei 2021 10:44 schreef Michael Van Canneyt via fpc-devel <
> fpc-devel@lists.freepascal.org>:
>
>>
>>
>> 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  -  fpc-devel@lists.freepascal.org
>> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>>
> ___
> fpc-devel maillist  -  fpc-devel@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] mantis 0038496 custom variants and documentation

2021-05-30 Thread Don Alfredo via fpc-devel
https://synopse.info/forum/viewtopic.php?id=5894

Op zo 30 mei 2021 10:44 schreef Michael Van Canneyt via fpc-devel <
fpc-devel@lists.freepascal.org>:

>
>
> 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  -  fpc-devel@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] mantis 0038496 custom variants and documentation

2021-05-30 Thread 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  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] mantis 0038496 custom variants and documentation

2021-05-29 Thread Marco van de Voort via fpc-devel
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 ?






___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel