我们想要在 Delphi 2009 和 Interbase 中使用 Unicode,并发现要将字符编码从 WIN1252 切换到 UNICODE_FSS 或 UTF8,我们首先必须在所有数据模块中将 TStringField 的所有实例替换为 TWideStringField。对于大约 60 个数据模块,我们不能简单地在一个周末完成这一工作。我只能看到迁移策略的两个选项:
- 找到一种解决方法,允许使用现有的 TStringField 字段而不触发“预期:TWideStringField”错误
或
据我所知字段类型持久数据库字段在某种类注册表中注册。我们可以使用它来让 Delphi 相信 TStringField 对于具有 UNICODE_FSS 或 UTF8 编码的 Interbase 字符列来说是可以的吗?
或者我们可以使用在这两种情况下都可以与 TStringField 一起使用的商业 dbExpress 驱动程序吗?
另请参阅我的相关问题: Delphi dbExpress 和 Interbase:UTF8 迁移步骤和风险?
更新:在所有 DFM 和 PAS 文件中将所有出现的 TStringField 替换为 TWideStringField 后,我们发现现在还需要将 TWideStringFields 的“Size”属性值乘以四(如果我们在大约 100 个地方使用 UTF8)。因此,我开始悬赏寻找一种减少修复 DFM 的手动工作的方法
We want to use Unicode with Delphi 2009 and Interbase, and found that to switch the character encoding from WIN1252 to UNICODE_FSS or UTF8 we first have to replace all instances of TStringField with TWideStringField in all datamodules. For around 60 datamodules, we can not simply do this over one weekend. I can see only two options for a migration strategy:
- find a workaround which allows to use the existing TStringField fields without triggering the 'expected: TWideStringField' error
or
- remove all persistent fields to avoid the string type conflict
As far as I know the field types for persistent database fields are registered in some kind of class registry. Could we use this to make Delphi believe that a TStringField is ok for a Interbase character column with UNICODE_FSS or UTF8 encoding?
Or can we use a commercial dbExpress driver which work with TStringField in both cases?
See also my related question: Delphi dbExpress and Interbase: UTF8 migration steps and risks?
Update: after replacing all occurences of TStringField with TWideStringField in all DFM and PAS files, we found that it is now also necessary to multiply the 'Size' property value of the TWideStringFields by four (if we use UTF8) in some 100 places. So I start a bounty for a way to reduce the manual work to fix the DFMs
发布评论
评论(1)
对 unicode 字符使用 TStringField 会给你带来麻烦,它里面会有 $00,基本上以 dbExpress 驱动程序结束字符串,因为这些驱动程序接受 P(Ansi)Char 字符串。使用 TWideStringField 在 dbExpress 中使用 PWideChar,因此驱动程序需要真正的 unicode 代码点。
恐怕没有简单的出路。
Using TStringField for unicode characters will get you into trouble, it will have $00 in it, basically ending the string with, for example, dbExpress drivers, as these accept P(Ansi)Char strings. Using TWideStringField uses PWideChar in dbExpress, so the driver is expecting true unicode codepoints.
There's no easy way out, I'm afraid.