Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-12

TField.AsInteger on text field

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Paul van Helden

Hi All,

A client has changed a field type in a SQLite db from INTEGER to TEXT. My app now crashes on a AField.AsInteger:=1; (Invalid type conversion to integer in field...)

Should the correct behaviour not be to simply convert to text in the AsInteger setter and attempt StrToInt in the getter before raising an exception?

Thanks,

Paul.

Reply by email

Michael Van Canneyt
to Paul van Helden
Paul van Helden wrote 9 lines
Hi All, A client has changed a field type in a SQLite db from INTEGER to TEXT. My app now crashes on a AField.AsInteger:=1; (Invalid type conversion to integer in field...) Should the correct behaviour not be to simply convert to text in the AsInteger setter and attempt StrToInt in the getter before raising an exception?

First of all, your client should not change the field type. If you use persistent fields, opening the dataset will go wrong, as a TIntegerField is declared, and the query will expect a TStringField to be present.

As for attempting to converting string fields to integer, this is debatable; I'm not particularly against it, but I'm not yet sure of all the consequences.

Please post a feature request in the FPC bugtracker.

Michael.

Reply by email