WideChar和AnsiChar有什么区别? [英] What is the difference between WideChar and AnsiChar?

查看:134
本文介绍了WideChar和AnsiChar有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在升级一些古代(从2003年)的Delphi代码到Delphi Architect XE,我遇到了一些问题。我遇到不符合类型的错误。这些错误不会发生在Delphi 6中,所以我必须假设这是因为事情已经升级。



我真的不知道PAnsiChar和PWideChar之间的区别是什么,但Delphi肯定知道差异,不会让我编译。如果我知道差异是什么,也许我可以弄清楚使用哪个或如何解决这个问题。

解决方案

简短:在Delphi 2009之前,Delphi中的本机字符串类型曾经是ANSI CHAR:每个字符串中的每个字符都表示为8位字符。 Delphi 2009开始Delphi的字符串变成UNICODE,使用UTF-16表示法:现在基本的Char使用16位数据(2字节),你可能不需要太多关于Unicode代码点被表示为两个连续16位字符。



8位字符称为Ansi Chars。 PAnsiChar是一个指向8位字符的指针。
16位字符称为宽字符。一个PWideChar是一个16位字符的指针。
德尔福知道差异,如果不允许你混合使用两者,则表现不错!



更多信息



以下是Unicode的热门链接:绝对最低每软件开发人员绝对必须了解Unicode和字符集



您可以在这里找到有关将Delphi迁移到Unicode的更多信息:新白皮书:Delphi Unicode Migration for Mere Mortals



您可以还可以搜索Delphi Unicode迁移。


I'm upgrading some ancient (from 2003) Delphi code to Delphi Architect XE and I'm running into a few problems. I am getting a number of errors where there are incompatible types. These errors don't happen in Delphi 6 so I must assume that this is because things have been upgraded.

I honestly don't know what the difference between PAnsiChar and PWideChar is, but Delphi sure knows the difference and won't let me compile. If I knew what the differences were maybe I could figure out which to use or how to fix this.

解决方案

The short: prior to Delphi 2009 the native string type in Delphi used to be ANSI CHAR: Each char in every string was represented as an 8 bit char. Starting with Delphi 2009 Delphi's strings became UNICODE, using the UTF-16 notation: Now the basic Char uses 16 bits of data (2 bytes), and you probably don't need to know much about the Unicode code points that are represented as two consecutive 16 bits chars.

The 8 bit chars are called "Ansi Chars". An PAnsiChar is a pointer to 8 bit chars. The 16 bit chars are called "Wide Chars". An PWideChar is a pointer to 16 bit chars. Delphi knows the difference and does well if it doesn't allow you to mix the two!

More info

Here's a popular link on Unicode: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets

You can find some more information on migrating Delphi to Unicode here: New White Paper: Delphi Unicode Migration for Mere Mortals

You may also search SO for "Delphi Unicode migration".

这篇关于WideChar和AnsiChar有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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