Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003924 [JEDI VCL] 00 JVCL Components major always 2006-09-25 12:56 2007-01-04 03:49
Reporter adrianonantua View Status public  
Assigned To obones
Priority normal Resolution fixed  
Status resolved   Product Version 3.10
Summary 0003924: TJvDBCalcEdit does not work correctly with FMTBCD fields
Description TJvDBCalcEdit 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!
Additional Information
Tags No tags attached.
Attached Files zip file icon TJvDBCalcEdit BUG.zip [^] (22,719 bytes) 2006-09-29 08:03

- Relationships

-  Notes
(0010236)
obones (administrator)
2006-09-29 06:42

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.
(0010255)
adrianonantua (reporter)
2006-09-29 08:06

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.
(0010302)
obones (administrator)
2006-10-06 02:55

Which function is that in? UpdateFieldData?
And if yes, what about the code inside DataChange?
(0010322)
adrianonantua (reporter)
2006-10-06 08:24
edited on: 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.

(0010519)
obones (administrator)
2007-01-04 03:48

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-09-29 08:07 adrianonantua Issue Monitored: adrianonantua
2006-09-29 08:10 adrianonantua Issue End Monitor: adrianonantua
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


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker