View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0003924||JEDI VCL||00 JVCL Components||public||2006-09-25 12:56||2007-01-04 03:49|
|Target Version||Fixed in Version||3.30|
|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!
|Tags||No tags attached.|
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.
TJvDBCalcEdit BUG.zip (22,719 bytes)
||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.|
Which function is that in? UpdateFieldData?
And if yes, what about the code inside DataChange?
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;
if not GetValue(bcd) then
Result := 0
Result := BcdToDouble(bcd);
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);
procedure TFMTBCDField.SetAsCurrency(Value: Currency);
VMax, VMin: Variant;
CurrToBcd(Value, FValue, MaxBcdPrecision, MaxBcdScale);
if FCheckRange then
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);
//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.
||This is now fixed in SVN.|
|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|