Page 1 of 1

Bug with variables

Posted: Tue Apr 14, 2020 10:41 pm
by dmajkic
We are using one variable as coefficient for some calculations. We are encountering a bug if number has decimals.

On HB side we have this:

Code: Select all

nBol := 0.65
oFR:AddVariable("_BOL", nBol)

on FR side, we have this:

Code: Select all

[<SomeField>*<_BOL>]


The issue is that variables in FR are exclusively strings. And our 0.65 gets converted to 0,65 (if locale uses coma as decimal separator)
And then expresion on FR side raises exception, as it expects US/Pascal numbers (with decimal point) in field expresions
If we format 0.65 to string, and call AddVariable() -> FRX wil add quotes: '0.65' and that also will not work in expresions.

We need a way to format our own string and send it to FR without quotes.

Is there any way we could do this?

Re: Bug with variables

Posted: Wed Apr 15, 2020 8:53 pm
by ignacio
Hello,

FRX can add variables as numbers. Try this:

[<_BOL>+10]

It should print 10.65

Regards

Re: Bug with variables

Posted: Fri Apr 17, 2020 9:38 am
by dmajkic
FRX can add variables as numbers. Try this:


This will not work. If windows locale is set to Serbian Latin, where numbers are formated as 123,00

_BOL gets converted to 0,65 (note the coma), and expresion is [0,65+10] which raises exception.

If we format _BOL as string :AddVariable("_BOL", "0.65") FRX will add quotes, and our expression is ['0.65' + 10] which also raises exception.

We solved it by inheriting FastReport class, add calling :SetCargo(STR(_BOL)), :AddVariableC("_BOL"),
wich works as expected - we have [0.65 + 10] regardless of system locale.

Re: Bug with variables

Posted: Fri Apr 17, 2020 10:40 am
by ignacio
Hi,

This will not work. If windows locale is set to Serbian Latin, where numbers are formated as 123,00


Is the same case in Spanish and here is working fine. :shock:

If we format _BOL as string :AddVariable("_BOL", "0.65") FRX will add quotes, and our expression is ['0.65' + 10] which also raises exception.


Logical. On that case you could use the FR function StringToFloat() (or something similar)

We solved it by inheriting FastReport class, add calling :SetCargo(STR(_BOL)), :AddVariableC("_BOL"),
wich works as expected - we have [0.65 + 10] regardless of system locale.


Glad you solve it. Thank you for the feedback.

Regards,

Re: Bug with variables

Posted: Thu Apr 30, 2020 3:25 am
by nbatocanin
This only partially solved the problem, I think there is a bug in FR. Would it help to make one simple example with this error?

NB