Ansichar和char之间有什么区别? [英] What is the difference between Ansichar and char?

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

问题描述

我最近遇到这种数据类型不匹配。这是我从来没有见过的。我希望有人可以解释这些是什么,他们有什么不同。



我的错误是F2063。 [DCC错误] E2010不兼容的类型:'AnsiChar'和'Char'

解决方案

/ strong>类型实际上是 ANSIChar 类型的同义词。也就是说,表示来自ANSI代码页的字符的单字节。 注意: 这是一个简化,忽略了可能在ANSI字符串中遇到的多字节字符引起的复杂情况,但这个答案就足够了。



这对应于 String 类型实际上是 ANSIString 的同义词。



使用Delphi 2009, String Char 类型变为分别为 UnicodeString (具有附加功能的 WideString )和 WideChar 的同义词,反映了将Unicode转换为字符串和字符类型的本机格式。 WideChar 是一个2字节的值,表示Unicode的单个字符(或替代对的一半)。



因此,在Delphi在Delphi 2009之前,以下两个变量是兼容类型:

  var 
ach:ANSIChar;
ch:Char; //与ANSIChar同名

然而,在Delphi 2009及更高版本中,ch声明的含义发生变化:

  var 
ach:ANSIChar;
ch:Char; // WIDEChar的同义词

因此, ach ch 变量不再是兼容类型。



ie你得到这个错误的原因是你有一些已经使用 ANSIChar 类型和其他代码声明的代码,这些代码使用声明为类型 Char 的值。当使用旧版本的Delphi编译时,其中 Char = ANSIChar ,两组代码是兼容的,但在Delphi 2009和更高版本中, Char = WideChar ,因此两种类型 Char ANSIChar 不兼容。


I recently ran into this data type mismatch. This is I never saw before. I hope someone could explain what these are and how are they different.

Error I got was F2063. [DCC Error] E2010 Incompatible types: 'AnsiChar' and 'Char'

解决方案

Historically in Delphi, the Char type was effectively a synonym for the ANSIChar type. That is, a single byte representing a character from an ANSI codepage. NOTE: This is a simplification that ignores the complications arising from multibyte characters which could be encountered in an ANSI string but will suffice for this answer.

This corresponded with the fact that the String type was effectively a synonym for ANSIString.

In Delphi 2009 onward, this changed.

With Delphi 2009, the String and Char types became synonyms for UnicodeString (a WideString with additional capabilities) and WideChar, respectively, reflecting the transition to Unicode as the native format for string and character types. A WideChar is a 2 byte value representing a single character of Unicode (or one half of a surrogate pair).

Therefore, in versions of Delphi prior to Delphi 2009, the following two variables were of compatible types:

var
  ach: ANSIChar;
  ch: Char;         // Synonymous with ANSIChar

However, in Delphi 2009 and later the meaning of the "ch" declarations changes:

var
  ach: ANSIChar;
  ch: Char;         // Synonymous with WIDEChar

As a result, the ach and ch variables are no longer of compatible types.

i.e. the reason you are getting this error is that you have some code which has been declared with ANSIChar types and other code which is using values declared of type Char. When compiled with an old version of Delphi where Char = ANSIChar, the two sets of code are compatible, but in Delphi 2009 and later Char = WideChar and so the two types (Char and ANSIChar) are not compatible.

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

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