delphi2009及以上版本中String与PAnsiChar转换

相关资料:
http://blog.sina.com.cn/s/blog_140f86bd70102xs49.html
 
在winsock编程中,使用api函数 inet_addr将ip地址转换成网络字节序时,传入参数类型为直接将string转换成PAnsiChar类型,转换出来的网络字节有错误,无法使用该ip,解决办法如下:

所有的原生字符串类型String转PAnsiChar都需要经过AnsiString过渡
strAnsi:= PAnsiChar(AnsiString(str));

 
其原因如下:

In D2009 and later: yes, there is. PChar is a pointer to a Char which is a unicode character (a WideChar). And PAnsiChar is a pointer to a AnsiChar, which is - as the name implies - an ANSI character.

 

EDIT: For pre-2009 versions of Delphi PChar and PAnsiChar are exactly the same. They both point to an (Ansi) character.

delphi2009及以上版本中String与PAnsiChar转换

上一篇:RestFul API接口设计风格介绍和核心功能(概念)


下一篇:C# Format格式化字符串的基本操作