Can I configure a TStringField to work as a TWideStringField in Delphi?

We want to use Unicode with Delphi 2009 and Interbase and found that to switch character encoding from WIN1252 to UNICODE_FSS or UTF8, we first need to replace all instances of TStringField with TWideStringField in all datamodules. For about 60 Damodules we can’t just do it in one weekend. I see only two options for the migration strategy:

  • find a workaround that allows you to use existing TStringField fields without causing the "expected: TWideStringField" error

or

  • remove all constant fields to avoid row type conflict.

As far as I know, field types for persistent database fields are registered in some class registry. Can we use this so that Delphi believes that TStringField is suitable for a column with an Interbase character encoded with UNICODE_FSS or UTF8?

Or can we use a commercial dbExpress driver that works with TStringField in both cases?

See also my related question: Delphi dbExpress and Interbase: steps and risks of migrating UTF8?


Update: after replacing all occurrences of TStringField with TWideStringField in all DFM and PAS files, we found that now we also need to multiply the value of the TWideStringFields Size property by four (if we use UTF8) in about 100 places. So I start bounty to reduce manual work, to fix DFM

+3
unicode migration delphi dbexpress interbase
source share
2 answers

Using TStringField for Unicode characters will cause you problems, it will have $ 00, basically the line ends with, for example, dbExpress drivers, since they accept P (Ansi) Char strings. Using TWideStringField uses PWideChar in dbExpress, so the driver expects true unicode codes.

There is no easy way out, I'm afraid.

+2
source share

Sergey A Kryukov, “Unicode Management: What Can VCL Do?”, “Delphi Journal”, 116 (April 2005), pp. 33-43 ( Source ) Delphi Journal

Unfortunately, the text of the original article is not freely available, but ask me if you have questions. 
-one
source share

All Articles