Browse Source

* fix bug #8244

git-svn-id: trunk@6550 -
joost 18 years ago
parent
commit
d868c00f8a
2 changed files with 27 additions and 30 deletions
  1. 4 2
      fcl/db/db.pp
  2. 23 28
      fcl/db/fields.inc

+ 4 - 2
fcl/db/db.pp

@@ -555,9 +555,11 @@ type
 
   TFloatField = class(TNumericField)
   private
+    FCurrency: Boolean;
     FMaxValue : Double;
     FMinValue : Double;
     FPrecision : Longint;
+    procedure SetCurrency(const AValue: Boolean);
   protected
     function GetAsFloat: Double; override;
     function GetAsLongint: Longint; override;
@@ -575,6 +577,7 @@ type
     property Value: Double read GetAsFloat write SetAsFloat;
 
   published
+    property Currency: Boolean read FCurrency write SetCurrency;
     property MaxValue: Double read FMaxValue write FMaxValue;
     property MinValue: Double read FMinValue write FMinValue;
     property Precision: Longint read FPrecision write FPrecision default 15;
@@ -585,7 +588,6 @@ type
   TCurrencyField = class(TFloatField)
   public
     constructor Create(AOwner: TComponent); override;
-    procedure GetText(var TheText: string; ADisplayText: Boolean); override;
   end;
 
 { TBooleanField }
@@ -1756,7 +1758,7 @@ const
       { ftWord} TLongintField,
       { ftBoolean} TBooleanField,
       { ftFloat} TFloatField,
-      { ftCurrency} Nil,
+      { ftCurrency} TCurrencyField,
       { ftBCD} TBCDField,
       { ftDate} TDateField,
       { ftTime} TTimeField,

+ 23 - 28
fcl/db/fields.inc

@@ -1554,6 +1554,12 @@ end;
 
 { TFloatField }
 
+procedure TFloatField.SetCurrency(const AValue: Boolean);
+begin
+  if FCurrency=AValue then exit;
+  FCurrency:=AValue;
+end;
+
 function TFloatField.GetAsFloat: Double;
 
 begin
@@ -1600,6 +1606,8 @@ procedure TFloatField.GetText(var TheText: string; ADisplayText: Boolean);
 Var
     fmt : string;
     E : Double;
+    Digits : integer;
+    ff: TFloatFormat;
 
 begin
   TheText:='';
@@ -1608,11 +1616,24 @@ begin
     Fmt:=FDisplayFormat
   else
     Fmt:=FEditFormat;
+    
+  Digits := 0;
+  if not FCurrency then
+    ff := ffGeneral
+  else
+    begin
+    Digits := CurrencyDecimals;
+    if ADisplayText then
+      ff := ffCurrency
+    else
+      ff := ffFixed;
+    end;
+
 
   If fmt<>'' then
     TheText:=FormatFloat(fmt,E)
   else
-    TheText:=FloatToStrF(E,ffgeneral,FPrecision,0);
+    TheText:=FloatToStrF(E,ff,FPrecision,Digits);
 end;
 
 procedure TFloatField.SetAsFloat(AValue: Double);
@@ -1676,35 +1697,9 @@ Constructor TCurrencyField.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);
   SetDataType(ftCurrency);
+  Currency := True;
 end;
 
-procedure TCurrencyField.GetText(var TheText: string; ADisplayText: Boolean);
-
-Var
-    fmt : string;
-    ff: TFloatFormat;
-    E : Double;
-
-begin
-  TheText:='';
-  If Not GetData(@E) then exit;
-  If ADisplayText or (Length(FEditFormat) = 0) Then
-    Fmt:=FDisplayFormat
-  else
-    Fmt:=FEditFormat;
-
-  if ADisplayText then
-    ff := ffCurrency
-  else
-    ff := ffFixed;
-
-  If fmt<>'' then
-    TheText:=FormatFloat(fmt, E)
-  else
-    TheText:=FloatToStrF(E, ff, FPrecision, CurrencyDecimals);
-end;
-
-
 { TBooleanField }
 
 function TBooleanField.GetAsBoolean: Boolean;