Página 1 de 1

Bug with variables

Publicado: Mar Abr 14, 2020 10:41 pm
por 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:

Código: Seleccionar todo

nBol := 0.65
oFR:AddVariable("_BOL", nBol)
on FR side, we have this:

Código: Seleccionar todo

[<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

Publicado: Mié Abr 15, 2020 8:53 pm
por ignacio
Hello,

FRX can add variables as numbers. Try this:

[<_BOL>+10]

It should print 10.65

Regards

Re: Bug with variables

Publicado: Vie Abr 17, 2020 9:38 am
por 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

Publicado: Vie Abr 17, 2020 10:40 am
por 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

Publicado: Jue Abr 30, 2020 3:25 am
por 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