Delphi XE5中移动平台的字符串要注意的事项


本文整理自网络,侵删。

 今天把项目往移动平台移植,遇到指针错误,无效地址访问.
XE5的单步调试速度太让人崩溃了.
发现错误出在一个字符串的循环上,我是for i:= 1 to length(字符串变量) do
结果报错.
看了一下XE5的DateType的帮助说明:
Note: All the string types described in this topic are supported by the Delphi desktop compilers (DCC32, DCC64, and DCCOSX).
However, the Delphi mobile compilers (DCCIOS32 and DCCIOSARM) support only the default string type (UnicodeString).
Also, with the Delphi mobile compilers, strings are 0-based and immutable; to manipulate strings, use the TStringHelper functions, which are provided for this purpose. For more information, see Migrating Delphi Code to Mobile from Desktop.

也就是在iOS和Android上字符串只有默认一种也就是UnicodeString.并且字符串的字符索引变成0开始的.而且字符串是不可变的.呃.
那我可怜的跨平台的代码啊.又要多很几行判断了.

判断方式有好多种,比如
{$IFDEF ANDROID}{$IFDEF IOS}
或者干脆如果处理器是ARM处理器就认为是移动代码
{$IF defined(CPUARM)}

补充一个悲剧的发现,尽管在移动代码中字符串以0为起始,但是Pos(‘a','abc')函数返回的还是1.
var
s:string;
s := 'abc';
Delete(s,1,1);s变成'bc'
copy('abc',1,1);返回的是'a'
也就是系统函数还都是基于1的.

实际上易博龙鼓励我们使用TStringHelper的函数:remove,delete…这些都是基于0的.

可是我要写D7-XE5的跨平台通用功能就没办法了,TStringHelper是早期版本Delphi所不支持的.

 

来源:http://www.raysoftware.cn/?p=383

相关阅读 >>

Delphi如何获取硬盘所有的分区容量

Delphi xe5 android 获取网络状态

Delphi android 拨打电话

Delphi 用空格把 s 凑够 n 的长度

Delphi 将svg加载到timage控件

Delphi tradiogroup 单选分组框组件

Delphi利用系统环境变量获取常用系统目录

Delphi常用获取系统信息的函数单元

Delphi xe10 手机端错误提示:detected problems with api compatibility (visit g.co/dev/appcompat for more info

Delphi fdquery 判断记录为空

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...