Delphi BDE Double类型字段改为String类型
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该错误消息仅由
TFloatField
类型的字段创建,仅当TFieldDef
的DataType
值为ftFloat< 时才会创建该错误消息/代码>。仔细检查您是否已像您认为的那样更改了属性。
字段定义可以从字段本身填充。确保您更改了底层数据库架构,而不仅仅是
TTable
组件。That error message is only created by fields of type
TFloatField
, which is only created when theTFieldDef
has aDataType
value offtFloat
. 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 would just convert it to a float:
当您更改字段类型时,您是否也更改了架构中数据库的字段(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.