View Issue Details

IDProjectCategoryView StatusLast Update
0003924JEDI VCL00 JVCL Componentspublic2007-01-04 03:49
ReporteradrianonantuaAssigned Toobones 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.10 
Target VersionFixed in Version3.30 
Summary0003924: TJvDBCalcEdit does not work correctly with FMTBCD fields
DescriptionTJvDBCalcEdit does not work correctly with BCD or FMTBCD fields. I tested it with IBX and Firebird and I noticed that when the Field receives the value from the JvDBCalcEdit control with AsFloat property, the value is turned into Currency (4 decimal places), which turns out to be a considerable loss of information for fields with more than 4 decimal places (which is the reason I am using a FMTBCD field). I actually corrected the source code in my environment, and I am just letting you know where: around line 2132 (aproximately) I added the following lines:
  if FDataLink.Field.DataType in [ftFMTBcd, ftBCD] then
    FDataLink.Field.AsBCD := DoubleToBCD(Self.Value)
For the DoubleToBCD routine be available, I added FMTBcd unit in uses clause. Now, it works like a charm!
TagsNo tags attached.

Activities

obones

2006-09-29 06:42

administrator   ~0010236

Please use the latest SVN version from here: http://jvcl.sf.net/daily/

then let us know how it goes. If it still fails, please provide the zipped sources of a sample application showing this.

2006-09-29 08:03

 

TJvDBCalcEdit BUG.zip (22,719 bytes)

adrianonantua

2006-09-29 08:06

reporter   ~0010255

The BUG informed still exists in the latest version. The component does not consider BCD or FMTBCD Fields, specifically. In these fields' (TBCDField and TFMTBCDField) implementation (VCL), the AsFloat property internally converts the received float value to Currency, which considers only 4 decimal places. When you work with more than 4 decimal places (NUMERIC(18,6), for instance, which is the reason of working with BCD/FMTBCD fields), the value is rounded to 4 decimal places. Along with this note, I also sent an application (BDS2006) showing the problem.

obones

2006-10-06 02:55

administrator   ~0010302

Which function is that in? UpdateFieldData?
And if yes, what about the code inside DataChange?

adrianonantua

2006-10-06 08:24

reporter   ~0010322

Last edited: 2006-10-06 08:28

The function I corrected was indeed UpdateFieldData. You caught my attention, though, when you mentioned the DataChange function: it does mention BCD or FMTBCD fields, I did not correct it and it works. I did some research and here is why: take a look at the GetAsFloat and the SetAsFloat implementation of TFMTBcdField:

function TFMTBCDField.GetAsFloat: Double;
var
  bcd: TBcd;
begin
  if not GetValue(bcd) then
    Result := 0
  else
    Result := BcdToDouble(bcd);
end;

{
This function actually converts Bcd to Double. That’s why the DataChange function did not have to be corrected: the JvDBCalcEdit got the actual converted value
}

procedure TFMTBCDField.SetAsFloat(Value: Double);
begin
  SetAsCurrency(Value);
end;

procedure TFMTBCDField.SetAsCurrency(Value: Currency);
var
  VMax, VMin: Variant;
  FValue: TBcd;
begin
  CurrToBcd(Value, FValue, MaxBcdPrecision, MaxBcdScale);
  if FCheckRange then
  begin
    VMax := VarFMTBcdCreate(FMaxValue, Self.Precision, Self.Size);
    VMin := VarFMTBcdCreate(FMinValue, Self.Precision, Self.Size);
    if (Value < VMin) or (Value > VMax) then
      BcdRangeError(Value, VMin, VMax);
  end;
  SetData(@FValue, False);
end;

//the SetAsFloat uses the Currency conversion, which ignores decimal places from the fifth on.

You may think that “this is more a FTMBcd bug than a JvDBCalcEdit bug”. I thought so too at first glance. Then I extended my thinking: FTMBcd was created initially to handle fractioned numbers with high precision, focusing mainly on monetary transactions. They did not concern so much about Float type: if you want high precision, use Currency or BCD, that is just their approach, their point of view (maybe I would have done it differently, but who I am to question their implementation, if it is not a bug but a strategy, an approach?). They guarantee precision with the functions SetAsCurrency ans SetAsBCD. And that is what I altered in the UpdateFieldData function, I added the AsBcd when the field is BCD or FTMBCD.

obones

2007-01-04 03:48

administrator   ~0010519

This is now fixed in SVN.

Issue History

Date Modified Username Field Change
2006-09-25 12:56 adrianonantua New Issue
2006-09-29 06:42 obones Note Added: 0010236
2006-09-29 06:42 obones Status new => feedback
2006-09-29 08:03 adrianonantua File Added: TJvDBCalcEdit BUG.zip
2006-09-29 08:06 adrianonantua Note Added: 0010255
2006-10-06 02:55 obones Note Added: 0010302
2006-10-06 08:24 adrianonantua Note Added: 0010322
2006-10-06 08:26 adrianonantua Note Edited: 0010322
2006-10-06 08:28 adrianonantua Note Edited: 0010322
2007-01-04 03:48 obones Status feedback => resolved
2007-01-04 03:48 obones Fixed in Version => Daily / SVN
2007-01-04 03:48 obones Resolution open => fixed
2007-01-04 03:48 obones Assigned To => obones
2007-01-04 03:48 obones Note Added: 0010519