Delphi BDE Double类型字段改为String类型

发布于 2024-09-15 14:41:34 字数 351 浏览 1 评论 0原文

我正在使用 BDE TTable,其中某些字段最初是 ftDouble。 因为要存储的输入有时是非数字的,所以我现在将字段类型更改为 ftString。

该字段的输入是通过 TEdit 完成的。当代码到达:

   with tblDM do
   begin
      Edit;
      FieldByName('s01_amt').AsString := Edit1.Text;
      Post;
   end;

如果输入不是数字,我会收到 BDE 错误:

“a”不是有效的浮点数 字段“s01_amt”的值。

I'm using a BDE TTable which had certain fields which were originally ftDouble.
Because the input to be stored is sometimes non-numeric, I now changed the field type to ftString.

Input into the field is done with a TEdit. When the code gets to:

   with tblDM do
   begin
      Edit;
      FieldByName('s01_amt').AsString := Edit1.Text;
      Post;
   end;

if the entry is not a number, I get the BDE error:

'a' is not a valid floating point
value for field 's01_amt'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧时浪漫 2024-09-22 14:41:34

该错误消息仅由 TFloatField 类型的字段创建,仅当 TFieldDefDataType 值为 ftFloat< 时才会创建该错误消息/代码>。仔细检查您是否已像您认为的那样更改了属性。

字段定义可以从字段本身填充。确保您更改了底层数据库架构,而不仅仅是 TTable 组件。

That error message is only created by fields of type TFloatField, which is only created when the TFieldDef has a DataType value of ftFloat. Double-check that you've changed the property think you did.

The field definitions can be populated from the fields themselves. Make sure you've changed the underlying database schema and not just your TTable component.

画▽骨i 2024-09-22 14:41:34

我只是将其转换为浮点数:

var
dFloat : double;

begin
  try dFloat := strToFloat(edit1.txt); except dFloat := 0; end;

  edit;
  FieldByName('s01_amt').AsFloat := dFloat;
  post;

end;

I would just convert it to a float:

var
dFloat : double;

begin
  try dFloat := strToFloat(edit1.txt); except dFloat := 0; end;

  edit;
  FieldByName('s01_amt').AsFloat := dFloat;
  post;

end;
故人爱我别走 2024-09-22 14:41:34

当您更改字段类型时,您是否也更改了架构中数据库的字段(xBASE/Clipper 中的结构)?如果不是,则您正在尝试将非数字值分配给数字类型字段,这就是导致异常的原因。

如果您仍在使用 DBF 样式文件,则需要将数据库中的字段类型从 NUMERIC 更改为 CHARACTER。您可以使用数据库桌面 IIRC 中的 SQL 以及 BDE 的 DBASE 支持来完成此操作。

仅将 TField 的类型从 ftFloat 更改为 ftString 不会自动更改该字段的数据库存储;你必须自己在这两个地方做。

When you changed the field type, did you also change the database's field in the schema (structure in xBASE/Clipper)? If not, you're trying to assign a non-numeric value to a numeric type field, and that's what's causing the exception.

If you're still using DBF style files, you need to change the type of the field in the database from NUMERIC to CHARACTER. You can do it using SQL from the Database Desktop, IIRC, with the BDE's DBASE support.

Just changing the TField's type from ftFloat to ftString won't alter the database storage for that field automatically; you have to do it in both places yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文