阅读 75

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.

原文:https://www.cnblogs.com/FKdelphi/p/13622498.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐