Browse Source

fcl-db: implement setter and getter for TFloatField.AsBCD

git-svn-id: trunk@29758 -
lacak 10 years ago
parent
commit
9fbf3494b4
2 changed files with 22 additions and 6 deletions
  1. 2 0
      packages/fcl-db/src/base/db.pas
  2. 20 6
      packages/fcl-db/src/base/fields.inc

+ 2 - 0
packages/fcl-db/src/base/db.pas

@@ -637,6 +637,7 @@ type
     procedure SetCurrency(const AValue: Boolean);
     procedure SetCurrency(const AValue: Boolean);
     procedure SetPrecision(const AValue: Longint);
     procedure SetPrecision(const AValue: Longint);
   protected
   protected
+    function GetAsBCD: TBCD; override;
     function GetAsFloat: Double; override;
     function GetAsFloat: Double; override;
     function GetAsLargeInt: LargeInt; override;
     function GetAsLargeInt: LargeInt; override;
     function GetAsInteger: Longint; override;
     function GetAsInteger: Longint; override;
@@ -644,6 +645,7 @@ type
     function GetAsString: string; override;
     function GetAsString: string; override;
     function GetDataSize: Integer; override;
     function GetDataSize: Integer; override;
     procedure GetText(var theText: string; ADisplayText: Boolean); override;
     procedure GetText(var theText: string; ADisplayText: Boolean); override;
+    procedure SetAsBCD(const AValue: TBCD); override;
     procedure SetAsFloat(AValue: Double); override;
     procedure SetAsFloat(AValue: Double); override;
     procedure SetAsLargeInt(AValue: LargeInt); override;
     procedure SetAsLargeInt(AValue: LargeInt); override;
     procedure SetAsInteger(AValue: Longint); override;
     procedure SetAsInteger(AValue: Longint); override;

+ 20 - 6
packages/fcl-db/src/base/fields.inc

@@ -1778,6 +1778,15 @@ begin
     FPrecision := 2;
     FPrecision := 2;
 end;
 end;
 
 
+function TFloatField.GetAsBCD: TBCD;
+var f : Double;
+begin
+  if GetData(@f) then
+    Result := DoubleToBCD(f)
+  else
+    Result := NullBCD;
+end;
+
 function TFloatField.GetAsFloat: Double;
 function TFloatField.GetAsFloat: Double;
 
 
 begin
 begin
@@ -1809,11 +1818,11 @@ end;
 
 
 function TFloatField.GetAsString: string;
 function TFloatField.GetAsString: string;
 
 
-var R : Double;
+var f : Double;
 
 
 begin
 begin
-  If GetData(@R) then
-    Result:=FloatToStr(R)
+  If GetData(@f) then
+    Result:=FloatToStr(f)
   else
   else
     Result:='';
     Result:='';
 end;
 end;
@@ -1859,6 +1868,11 @@ begin
     TheText:=FloatToStrF(E,ff,FPrecision,Digits);
     TheText:=FloatToStrF(E,ff,FPrecision,Digits);
 end;
 end;
 
 
+procedure TFloatField.SetAsBCD(const AValue: TBCD);
+begin
+  SetAsFloat(BCDToDouble(AValue));
+end;
+
 procedure TFloatField.SetAsFloat(AValue: Double);
 procedure TFloatField.SetAsFloat(AValue: Double);
 
 
 begin
 begin
@@ -1881,15 +1895,15 @@ end;
 
 
 procedure TFloatField.SetAsString(const AValue: string);
 procedure TFloatField.SetAsString(const AValue: string);
 
 
-var R : Double;
+var f : Double;
 
 
 begin
 begin
   If (AValue='') then
   If (AValue='') then
     Clear
     Clear
   else  
   else  
     try
     try
-      R := StrToFloat(AValue);
-      SetAsFloat(R);
+      f := StrToFloat(AValue);
+      SetAsFloat(f);
     except
     except
       DatabaseErrorFmt(SNotAFloat, [AValue]);
       DatabaseErrorFmt(SNotAFloat, [AValue]);
     end;
     end;