Recent

Author Topic: TFMTBCDField - wrong range check  (Read 2574 times)

emilt

  • New Member
  • *
  • Posts: 26
TFMTBCDField - wrong range check
« on: January 08, 2022, 11:17:21 am »
With new Lazarus 2.2.0, an error started to appear on trying to update a TFMTBCDField:
Quote
error: 1.00 is not between 0.00 and 0.00

This only happens when I set the field's ProviderFlags to include pfRefreshOnUpdate. It also happens when I try to insert with pfRefreshOnInsert.

Don't know if it is relevant, this is a Firebird 3 DECIMAL(15, 6) field, and I'm using FPC's IBConnection.

Maybe someone could point me at least where to look? TFMTBCDField looks OK to me. The range error should not appear if at least one of MinValue and MaxValue are 0.


emilt

  • New Member
  • *
  • Posts: 26
Re: TFMTBCDField - wrong range check
« Reply #1 on: January 08, 2022, 04:06:41 pm »
OK, found it!
https://gitlab.com/freepascal.org/fpc/source/-/commit/573917706fb5a5cffd76239e90ef62fdee041f68

The patch works for me. It's in FPC's RTL, so this must be rebuilt. I used
Code: Text  [Select][+][-]
  1. fppkg install
from the fpc\3.2.2\source\packages\rtl-objpas directory.

brick08

  • Newbie
  • Posts: 4
Re: TFMTBCDField - wrong range check
« Reply #2 on: January 14, 2022, 05:50:03 am »
This happens because when converting zero from a string and an integer, you get a different Precision.
Try it:
Code: Pascal  [Select][+][-]
  1. var
  2.   bcd, sbcd, ibcd: tBCD;
  3. begin
  4.   ibcd:=IntegerToBCD(0);
  5.   sbcd:=StrToBCD('0');
  6.   if sbcd = ibcd then
  7.     ShowMessage('Equals')
  8.   else
  9.     ShowMessage('Not Equals');
  10.   if sbcd = 0 then
  11.     ShowMessage('sbcd = 0')
  12.   else
  13.     ShowMessage('sbcd <> 0');
  14.   if ibcd = 0 then
  15.     ShowMessage('ibcd = 0')
  16.   else
  17.     ShowMessage('ibcd <> 0');
  18.  


this patch helps me too, problem done
« Last Edit: January 14, 2022, 07:55:10 am by brick08 »

 

TinyPortal © 2005-2018