tags:

views:

62

answers:

3

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'.

A: 

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;
Don Dickinson
Sorry, I wasn't clear in my question. The reason for the change in the field type, is that the information stored can be non-numeric.
ChuckO
A: 

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.

Ken White
I used dBASE to change the field type from NUMERIC to CHARACTER in the DBF file.I called it ftString in the question to conform to Delphi usage.
ChuckO
Something here is not consistent. Do you have any persistent fields (fields created at designtime with the Fields Editor) on the table? It's possible that assignment using FieldByName() in one place to set the content is causing a refresh in the persistent field somewhere else, and that's what's actually causing the error.
Ken White
+1  A: 

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.

Rob Kennedy
The FieldDefs property on the TTable component shows that the field is ftString
ChuckO
I had no doubt of that — you *said* you changed it to ftString in the question. But TTable is not the database schema. Check the database schema.
Rob Kennedy
I used dBASE to change the field type from NUMERIC to CHARACTER in the DBF file. I called it ftString in the question to conform to Delphi usage.
ChuckO