开发者

Delphi BDE Double type Field changed to a String type

I'm using a BDE TTable开发者_如何学Go 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'.


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 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;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜