Browse Source

+ Patch from Joost van der Sluis to correct AsVariant

michael 20 years ago
parent
commit
a31b420eb1
1 changed files with 116 additions and 1 deletions
  1. 116 1
      fcl/db/fields.inc

+ 116 - 1
fcl/db/fields.inc

@@ -231,6 +231,7 @@ Const
   SDateTime = 'TDateTime';
   SDateTime = 'TDateTime';
   SFloat = 'Float';
   SFloat = 'Float';
   SInteger = 'Integer';
   SInteger = 'Integer';
+  SVariant = 'Variant';
   SString = 'String';
   SString = 'String';
 
 
 constructor TField.Create(AOwner: TComponent);
 constructor TField.Create(AOwner: TComponent);
@@ -327,6 +328,13 @@ begin
   AccessError(SInteger);
   AccessError(SInteger);
 end;
 end;
 
 
+function TField.GetAsVariant: Variant;
+
+begin
+  AccessError(SVariant);
+end;
+
+
 function TField.GetAsInteger: Integer;
 function TField.GetAsInteger: Integer;
 
 
 begin
 begin
@@ -339,6 +347,20 @@ begin
   AccessError(SString);
   AccessError(SString);
 end;
 end;
 
 
+function TField.GetOldValue: Variant;
+
+var SaveState : tDatasetState;
+
+begin
+  with FDataset do
+    begin
+    SaveState := State;
+    SetTempState(dsOldValue);
+    Result := GetAsVariant;
+    RestoreState(SaveState);
+    end;
+end;
+
 function TField.GetCanModify: Boolean;
 function TField.GetCanModify: Boolean;
 
 
 begin
 begin
@@ -482,6 +504,13 @@ begin
   AccessError(SFloat);
   AccessError(SFloat);
 end;
 end;
 
 
+procedure TField.SetAsVariant(AValue: Variant);
+
+begin
+  AccessError(SVariant);
+end;
+
+
 procedure TField.SetAsLongint(AValue: Longint);
 procedure TField.SetAsLongint(AValue: Longint);
 
 
 begin
 begin
@@ -699,6 +728,18 @@ begin
     Result:='';
     Result:='';
 end;
 end;
 
 
+function TStringField.GetAsVariant: Variant;
+
+Var s : string;
+
+begin
+  If GetValue(s) then
+    Result:=s
+  else
+    Result:=Null;
+end;
+
+
 function TStringField.GetDataSize: Word;
 function TStringField.GetDataSize: Word;
 
 
 begin
 begin
@@ -831,6 +872,17 @@ begin
     Result:=0;
     Result:=0;
 end;
 end;
 
 
+function TLongintField.GetAsVariant: Variant;
+
+Var L : Longint;
+
+begin
+  If GetValue(L) then
+    Result:=L
+  else
+    Result:=Null;
+end;
+
 function TLongintField.GetAsString: string;
 function TLongintField.GetAsString: string;
 
 
 Var L : Longint;
 Var L : Longint;
@@ -902,6 +954,12 @@ begin
     RangeError(Avalue,FMinrange,FMaxRange);
     RangeError(Avalue,FMinrange,FMaxRange);
 end;
 end;
 
 
+procedure TLongintField.SetAsVariant(AValue: Variant);
+
+begin
+  SetAsLongint(AValue);
+end;
+
 procedure TLongintField.SetAsString(const AValue: string);
 procedure TLongintField.SetAsString(const AValue: string);
 
 
 Var L,Code : longint;
 Var L,Code : longint;
@@ -984,6 +1042,17 @@ begin
     Result:=0;
     Result:=0;
 end;
 end;
 
 
+function TLargeIntField.GetAsVariant: Variant;
+
+Var L : Largeint;
+
+begin
+  If GetValue(L) then
+    Result:=L
+  else
+    Result:=Null;
+end;
+
 function TLargeintField.GetAsLongint: Longint;
 function TLargeintField.GetAsLongint: Longint;
 
 
 begin
 begin
@@ -1173,6 +1242,17 @@ begin
     Result:=0.0;
     Result:=0.0;
 end;
 end;
 
 
+function TFloatField.GetAsVariant: Variant;
+
+Var f : Double;
+
+begin
+  If GetData(@f) then
+    Result := f
+  else
+    Result:=Null;
+end;
+
 function TFloatField.GetAsLongint: Longint;
 function TFloatField.GetAsLongint: Longint;
 
 
 begin
 begin
@@ -1270,6 +1350,17 @@ begin
     Result:=False;
     Result:=False;
 end;
 end;
 
 
+function TBooleanField.GetAsVariant: Variant;
+
+Var b : boolean;
+
+begin
+  If GetData(@b) then
+    Result := b
+  else
+    Result:=Null;
+end;
+
 function TBooleanField.GetAsString: string;
 function TBooleanField.GetAsString: string;
 
 
 Var B : boolean;
 Var B : boolean;
@@ -1353,6 +1444,16 @@ begin
     Result:=0;
     Result:=0;
 end;
 end;
 
 
+function TDateTimeField.GetAsVariant: Variant;
+
+Var d : tDateTime;
+
+begin
+  If Getdata(@d) then
+    Result := d
+  else
+    Result:=Null;
+end;
 
 
 function TDateTimeField.GetAsFloat: Double;
 function TDateTimeField.GetAsFloat: Double;
 
 
@@ -1583,6 +1684,17 @@ begin
     result := C;
     result := C;
 end;
 end;
 
 
+function TBCDField.GetAsVariant: Variant;
+
+Var c : system.Currency;
+
+begin
+  If GetData(@c) then
+    Result := c
+  else
+    Result:=Null;
+end;
+
 function TBCDField.GetAsFloat: Double;
 function TBCDField.GetAsFloat: Double;
 
 
 begin
 begin
@@ -2095,7 +2207,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.19  2004-12-13 19:20:42  michael
+  Revision 1.20  2004-12-29 20:27:08  michael
+  + Patch from Joost van der Sluis to correct AsVariant
+
+  Revision 1.19  2004/12/13 19:20:42  michael
     * Patch from Joost van der Sluis
     * Patch from Joost van der Sluis
     - fixed bug #3180, TFields.Clear implemented
     - fixed bug #3180, TFields.Clear implemented
     - implemented TLargeintField
     - implemented TLargeintField