Field Types and Strings

It is interesting to notice how the different field types are mapped to different native string types. I'm specifically referring to the TStringField and TWideStringField types, of course. The Value property for these field types changed from earlier versions of Delphi, but it was kept the same until Delphi 2007, despite the changes in metadata support (including the field names, mentioned earlier):

Delphi 7 Delphi 2007 Delphi 2009

  1. Value string string AnsiString
  2. Value wideString WideString UnicodeString

In case your program uses a TWideStringField mapped to a Unicode string field of the database, the data is kept in Unicode format. What happens, instead, when you access the AsString property of a TStringField object? The implementation of the corresponding getter method remaps the access to the AsAnsiString method, that forces the conversion of the string buffer to the AnsiString type.

Notice that a TWideStringField object uses the same UTF-16 encoding of a UnicodeString in Delphi 2009, while a TStringField object uses the basic AnsiString type. You would need to write extra support code (which won't be trivial to write) for using a different code page or UTF-8 encoding with TStringField.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment