是否可以调整TStringField在Delphi中像TWideStringField一样工作? [英] Is it possible to tweak TStringField to work like TWideStringField in Delphi?

查看:578
本文介绍了是否可以调整TStringField在Delphi中像TWideStringField一样工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望使用Delphi 2009和Interbase中的Unicode,并发现将字符编码从WIN1252切换到UNICODE_FSS或UTF8,我们首先必须在所有数据模块中用TWideStringField替换所有的TStringField实例。对于约60个数据模块,我们不能简单地在一个周末做到这一点。我可以看到迁移策略只有两个选项:




  • 找到一个解决方法,允许使用现有的TStringField字段,而不会触发expected: TWideStringField'错误






  • 所有持久性字段避免字符串类型冲突



据我所知,持久数据库字段的字段类型已注册在某种类注册表。我们可以使用它来使Delphi相信一个TStringField对于具有UNICODE_FSS或UTF8编码的Interbase字符列可以吗?



或者我们可以使用商业dbExpress驱动程序在这两种情况下,TStringField?



另请参见我的相关问题: Delphi dbExpress和Interbase:UTF8迁移步骤和风险?






更新:在所有DFM和PAS文件中用TWideStringField替换所有出现的TStringField之后,我们发现现在还需要将TWideStringFields的Size属性值乘以4(如果我们使用UTF8)在大约100个地方。所以我开始一个赏金,以减少手动工作来修复DFM

解决方案

使用TStringField进行unicode字符会让你陷入麻烦,它将有$ 00,基本上结束字符串与例如dbExpress驱动程序,因为这些接受P(Ansi)Char字符串。使用TWideStringField在dbExpress中使用了PWideChar,因此驱动程序正在期待真正的unicode代码点。



恐怕没有简单的出路。


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

解决方案

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.

这篇关于是否可以调整TStringField在Delphi中像TWideStringField一样工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆