|
@@ -109,10 +109,8 @@ begin
|
|
TFloatField(Result).Precision:=FPrecision;
|
|
TFloatField(Result).Precision:=FPrecision;
|
|
if (Result is TBCDField) then
|
|
if (Result is TBCDField) then
|
|
TBCDField(Result).Precision:=FPrecision;
|
|
TBCDField(Result).Precision:=FPrecision;
|
|
- {Add when implemented:
|
|
|
|
if (Result is TFmtBCDField) then
|
|
if (Result is TFmtBCDField) then
|
|
TFmtBCDField(Result).Precision:=FPrecision;
|
|
TFmtBCDField(Result).Precision:=FPrecision;
|
|
- }
|
|
|
|
except
|
|
except
|
|
Result.Free;
|
|
Result.Free;
|
|
Raise;
|
|
Raise;
|
|
@@ -2395,6 +2393,184 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
+{ TFMTBCDField }
|
|
|
|
+
|
|
|
|
+class procedure TFMTBCDField.CheckTypeSize(AValue: Longint);
|
|
|
|
+begin
|
|
|
|
+ If AValue > MAXFMTBcdFractionSize then
|
|
|
|
+ DatabaseErrorfmt(SInvalidFieldSize,[AValue]);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+constructor TFMTBCDField.Create(AOwner: TComponent);
|
|
|
|
+begin
|
|
|
|
+ Inherited Create(AOwner);
|
|
|
|
+ FMaxValue := 0;
|
|
|
|
+ FMinValue := 0;
|
|
|
|
+ FValidChars := [DecimalSeparator, '+', '-', '0'..'9'];
|
|
|
|
+ SetDataType(ftFMTBCD);
|
|
|
|
+// Max.precision for NUMERIC,DECIMAL datatypes supported by some databases:
|
|
|
|
+// Firebird-18; Oracle,SqlServer-38; MySQL-65; PostgreSQL-1000
|
|
|
|
+ Precision := 15; //default number of digits
|
|
|
|
+ Size:=4; //default number of digits after decimal place
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetDataSize: Integer;
|
|
|
|
+begin
|
|
|
|
+ Result := sizeof(TBCD);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetDefaultWidth: Longint;
|
|
|
|
+begin
|
|
|
|
+ if Precision > 0 then Result := Precision+1
|
|
|
|
+ else Result := inherited GetDefaultWidth;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetAsBCD: TBCD;
|
|
|
|
+begin
|
|
|
|
+ if not GetData(@Result) then
|
|
|
|
+ Result := NullBCD;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetAsCurrency: Currency;
|
|
|
|
+var bcd: TBCD;
|
|
|
|
+begin
|
|
|
|
+ if GetData(@bcd) then
|
|
|
|
+ BCDToCurr(bcd, Result)
|
|
|
|
+ else
|
|
|
|
+ Result := 0;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetAsVariant: Variant;
|
|
|
|
+var bcd: TBCD;
|
|
|
|
+begin
|
|
|
|
+ If GetData(@bcd) then
|
|
|
|
+ Result := BCDToDouble(bcd)//remove when complete variant support in fmtbcd.pp will be implemented
|
|
|
|
+ //Result := VarFMTBcdCreate(bcd) //later invalid variant type cast ?
|
|
|
|
+ else
|
|
|
|
+ Result := Null;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetAsFloat: Double;
|
|
|
|
+var bcd: TBCD;
|
|
|
|
+begin
|
|
|
|
+ If GetData(@bcd) then
|
|
|
|
+ Result := BCDToDouble(bcd)
|
|
|
|
+ else
|
|
|
|
+ Result := 0;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetAsLongint: Longint;
|
|
|
|
+begin
|
|
|
|
+ Result := round(GetAsFloat);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetAsString: string;
|
|
|
|
+var bcd: TBCD;
|
|
|
|
+begin
|
|
|
|
+ If GetData(@bcd) then
|
|
|
|
+ Result:=BCDToStr(bcd)
|
|
|
|
+ else
|
|
|
|
+ Result:='';
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TFMTBCDField.GetText(var TheText: string; ADisplayText: Boolean);
|
|
|
|
+var
|
|
|
|
+ bcd: TBCD;
|
|
|
|
+ E: double; //remove when formatBCD,BCDToStrF in fmtbcd.pp will be implemented
|
|
|
|
+ fmt: String;
|
|
|
|
+begin
|
|
|
|
+ if GetData(@bcd) then begin
|
|
|
|
+ E:=BCDToDouble(bcd);
|
|
|
|
+ if aDisplayText or (FEditFormat='') then
|
|
|
|
+ fmt := FDisplayFormat
|
|
|
|
+ else
|
|
|
|
+ fmt := FEditFormat;
|
|
|
|
+ if fmt<>'' then
|
|
|
|
+ TheText := FormatFloat(fmt,E)
|
|
|
|
+ //TheText := FormatBCD(fmt,bcd)
|
|
|
|
+ else if fCurrency then begin
|
|
|
|
+ if aDisplayText then
|
|
|
|
+ TheText := FloatToStrF(E, ffCurrency, FPrecision, 2{digits?})
|
|
|
|
+ //TheText := BcdToStrF(bcd, ffCurrency, FPrecision, 2{digits?})
|
|
|
|
+ else
|
|
|
|
+ TheText := FloatToStrF(E, ffFixed, FPrecision, 2{digits?});
|
|
|
|
+ //TheText := BcdToStrF(bcd, ffFixed, FPrecision, 2{digits?});
|
|
|
|
+ end else
|
|
|
|
+ TheText := BcdToStr(bcd);
|
|
|
|
+ //TheText := BcdToStrF(bcd, ffGeneral, FPrecision, FSize);
|
|
|
|
+ end else
|
|
|
|
+ TheText := '';
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetMaxValue: string;
|
|
|
|
+begin
|
|
|
|
+ Result:=BCDToStr(FMaxValue);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TFMTBCDField.GetMinValue: string;
|
|
|
|
+begin
|
|
|
|
+ Result:=BCDToStr(FMinValue);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TFMTBCDField.SetMaxValue(const AValue: string);
|
|
|
|
+begin
|
|
|
|
+ FMaxValue:=StrToBCD(AValue);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TFMTBCDField.SetMinValue(const AValue: string);
|
|
|
|
+begin
|
|
|
|
+ FMinValue:=StrToBCD(AValue);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+Function TFMTBCDField.CheckRange(AValue: TBCD) : Boolean;
|
|
|
|
+begin
|
|
|
|
+ If (FMinValue<>0) or (FMaxValue<>0) then
|
|
|
|
+ Result:=(AValue>=FMinValue) and (AValue<=FMaxValue)
|
|
|
|
+ else
|
|
|
|
+ Result:=True;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TFMTBCDField.SetAsBCD(const AValue: TBCD);
|
|
|
|
+begin
|
|
|
|
+ if CheckRange(AValue) then
|
|
|
|
+ SetData(@AValue)
|
|
|
|
+ else
|
|
|
|
+ RangeError(AValue, BCDToDouble(FMinValue), BCDToDouble(FMaxValue));
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TFMTBCDField.SetAsCurrency(AValue: Currency);
|
|
|
|
+var bcd: TBCD;
|
|
|
|
+begin
|
|
|
|
+ if CurrToBCD(AValue, bcd, 32, Size) then
|
|
|
|
+ SetAsBCD(bcd);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TFMTBCDField.SetVarValue(const AValue: Variant);
|
|
|
|
+var E:double;
|
|
|
|
+begin
|
|
|
|
+ E:=AValue;
|
|
|
|
+ SetAsBCD(DoubleToBCD(E));//remove when VarToBCD in fmtbcd.pp will be implemented
|
|
|
|
+ //SetAsBCD(VarToBCD(AValue));
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TFMTBCDField.SetAsFloat(AValue: Double);
|
|
|
|
+begin
|
|
|
|
+ SetAsBCD(DoubleToBCD(AValue));
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+procedure TFMTBCDField.SetAsLongint(AValue: Longint);
|
|
|
|
+begin
|
|
|
|
+ SetAsBCD(IntegerToBCD(AValue));
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+procedure TFMTBCDField.SetAsString(const AValue: string);
|
|
|
|
+begin
|
|
|
|
+ SetAsBCD(StrToBCD(AValue));
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
{ TBlobField }
|
|
{ TBlobField }
|
|
|
|
|
|
Function TBlobField.GetBlobStream(Mode : TBlobStreamMode) : TStream;
|
|
Function TBlobField.GetBlobStream(Mode : TBlobStreamMode) : TStream;
|