简体   繁体   English

Paradox BCD 字段 - 数字超出范围错误

[英]Paradox BCD field - Number is out of Range error

I'm attempting to update an old Paradox (BDE) table using an older Delphi XE6 application.我正在尝试使用旧的 Delphi XE6 应用程序更新旧的 Paradox (BDE) 表。 One particular table has two fields;一个特定的表有两个字段; a Date field, and a BCD field.一个日期字段和一个 BCD 字段。 I'm unable to post a new record to the (FuelSurch) table due to the BCD (FuelSur) field which is throwing a "Number is out of range" error.由于 BCD (FuelSur) 字段抛出“数字超出范围”错误,我无法将新记录发布到 (FuelSurch) 表。

So I wrote a quick test, but still the same issue.所以我写了一个快速测试,但仍然是同样的问题。 Here are the FuelSurch table field specifications.以下是 FuelSurch 表字段规范。

在此处输入图片说明

I just added a button to a form and this procedure fires when clicked.我刚刚在表单中添加了一个按钮,单击时会触发此过程。

procedure TTestForm.BCDTestBtnClick(Sender: TObject);
var
  Bcd: TBcd;
begin
  POE_Data.FuelSurch.Open;
  POE_Data.FuelSurch.Insert;
  Bcd:= StrToBcd('2.01');
  showMessage('Bcd = ' + BcdToStr(Bcd));  // This works and shows 'Bcd = 2.01'
  POE_Data.FuelSurchFuelSur.AsBCD := Bcd;  // Line produces "Number is out of range." error
  POE_Data.FuelSurch.Post;
  POE_Data.FuelSurch.Close;
end;

The database connection is confirmed as good as I'm able to post to other tables.数据库连接已确认与我能够发布到其他表一样好。 It just seems like this BCD field type is giving me issues.似乎这个 BCD 字段类型给我带来了问题。

Do I need to format the string differently before assigning it to the Bcd variable?在将字符串分配给 Bcd 变量之前,是否需要对字符串进行不同的格式化?

Internally the precision of a BCD is the total number of digits, not the number of digits after the decimal separator. BCD 的内部精度是位数,而不是小数点分隔符后的位数。

It's always an even number (when odd, 1 is added to it).它始终是偶数(当为奇数时,加 1)。 The reason is that a byte stores 2 digits.原因是一个字节存储了 2 位数字。

So if you try this:所以如果你试试这个:

procedure TForm1.Button1Click(Sender: TObject);
var
  Bcd: TBCD;
begin
  Bcd := StrToBcd('2.01', TFormatSettings.Invariant);
  ShowMessage(IntToStr(Bcd.Precision));
end;

you will see 4, because 3 digits are used, plus 1 to make it even.您将看到 4,因为使用了 3 位数字,再加上 1 以使其相等。

Your field precision is only 2. If it represents the same as TBCD.Precision , it's not enough.你的字段精度只有 2。如果它表示与TBCD.Precision相同,那还不够。

Note that BcdPrecision() returns the number of digits before the decimal separator, which is a bit confusing.注意BcdPrecision()返回小数点分隔符之前的位数,这有点令人困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM