Page 1 of 1

[patch_done] Patch for DecimalSeparator on Lazarus/FPC

Posted: 12.09.2009, 17:05
by dopidaniel
Hi All,

Thanks a lot for Zeos... It's a great library... Recently I change from Delphi do Lazarus/FPC... so, I decide to use Zeos as replacement for ClientDataSet... I use Zeus with FireBird and now, SQLite...

In Brazil, we use comma ',' as Decimal Separator... I note a conversion problem, when Zeos read REAL/FLOAT Field types on SQLite (on FireBird works fine)... all Float fields returns Zero values... (If I change S.O. DecimalSeparator for Dot '.' everething works fine)

After dig, on Zeos Code, I found a correction for the problem...

On function ZSysUtils.SQLStrToFloatDef, there is a especific code to DecimalSeparator as comma ','... But I don't know way... STR parameter came with dot (even when DecimalSeparator is ','), maybe FPC, is doing some translation

So I changed a line in code, to verify If STR parameter realy use a diferente DecimalSeparator than Dot..

Code: Select all

Index: core/ZSysUtils.pas
===================================================================
--- core/ZSysUtils.pas	(revision 684)
+++ core/ZSysUtils.pas	(working copy)
@@ -511,7 +511,7 @@
   else
   begin
     {$IFDEF FPC}
-    if OldDecimalSeparator = ',' then
+    if pos(OldDecimalSeparator,Str) > 0 then
       begin
         DecimalSeparator := OldDecimalSeparator;
         Result := StrToFloatDef(Str, Def);

Posted: 12.09.2009, 17:09
by dopidaniel
I forgot to comment ... I'm using:

Lazarus 0.9.29 updated from SVN with FPC 2.3.1
ZeosLib 7.0.0-dev updated from SVN

Posted: 22.09.2009, 23:06
by mdaems
dopidaniel,

I believe this patch isn't needed as the {$IFDEF FPC} is different from the original Delphi implementation.
As some might have noticed, I ported the test suite to Fpcunit and when running the test suite for Lazarus/FPC now, there's quite a lot of bugs that don't show up for Delphi, exactly because of the 'special' ZSysUtils.SQLStrToFloatDef treatment.
This patch solves quite some of them:

Code: Select all

Index: ZSysUtils.pas
===================================================================
--- ZSysUtils.pas	(revision 693)
+++ ZSysUtils.pas	(working copy)
@@ -509,19 +509,7 @@
   If Str = '' then
     Result := Def
   else
-  begin
-    {$IFDEF FPC}
-    if OldDecimalSeparator = ',' then
-      begin
-        DecimalSeparator := OldDecimalSeparator;
-        Result := StrToFloatDef(Str, Def);
-      end
-    else
-        Result := StrToFloatDef(Str, Def);
-    {$ELSE}
     Result := StrToFloatDef(Str, Def);
-    {$ENDIF}
-  end;
   DecimalSeparator := OldDecimalSeparator;
 end;
 
What's your idea?

Mark

Posted: 23.09.2009, 13:03
by dopidaniel
Hi Mark,

Thanks for reply...

Yes, it works... I was thinking about to propose a patch like yours... but I was not sure why that IFDEF FPC was introduced... I was thinking about some old FPC compatibility...

I'm newbie on Lazarus/FPC and Zeos... so I don't feel to much confortable to say what's the best way... :)

(excuse my poor English)

Re: Patch for DecimalSeparator on Lazarus/FPC

Posted: 23.09.2009, 15:00
by mdaems
dopidaniel wrote: In Brazil, we use comma ',' as Decimal Separator...
So we do in Belgium ;)

I did commit the patch to testing branch already. (SVN rev. 697)
I'm just a little afraid to port the patch to the Stable branch as well... Who knows there's somebody having a positive effect of the old version?

Mark