在Delphi XE下,是否有ANSI版本的Copy?
我正在使用复制很多来复制ANSI字符串.
我正在使用复制很多来复制ANSI字符串.
解决方法
Altar在Delphi中的
Copy函数是一个内在函数,这意味着由编译器处理,而不是运行时库.取决于通过此函数的参数调用LStrCopy或UStrCopy内部函数
检查这个样本:
{$APPTYPE CONSOLE} uses SysUtils; Var s : AnsiString; u : string; begin try s:='this is a ansi string'; s:= Copy(s,1,5); Writeln(s); u:='this is a unicode string'; u:= Copy(u,5); Writeln(u); except on E: Exception do Writeln(E.ClassName,': ',E.Message); end; Readln; end.
现在检查汇编代码
Project91.dpr.12: s:='this is a ansi string'; 004111DC B8787E4100 mov eax,$00417e78 004111E1 BA04134100 mov edx,$00411304 004111E6 E8314FFFFF call @LStrAsg Project91.dpr.13: s:= Copy(s,5); 004111EB 68787E4100 push $00417e78 004111F0 B905000000 mov ecx,$00000005 004111F5 BA01000000 mov edx,$00000001 004111FA A1787E4100 mov eax,[$00417e78] 004111FF E8A050FFFF call @LStrCopy //call the ansi version of copy Project91.dpr.14: Writeln(s); 00411204 A1EC2C4100 mov eax,[$00412cec] 00411209 8B15787E4100 mov edx,[$00417e78] 0041120F E84033FFFF call @Write0LString 00411214 E8DF33FFFF call @WriteLn 00411219 E8D22AFFFF call @_IOTest Project91.dpr.15: u:='this is a unicode string'; 0041121E B87C7E4100 mov eax,$00417e7c 00411223 BA28134100 mov edx,$00411328 00411228 E8534EFFFF call @UStrAsg Project91.dpr.16: u:= Copy(u,5); 0041122D 687C7E4100 push $00417e7c 00411232 B905000000 mov ecx,$00000005 00411237 BA01000000 mov edx,$00000001 0041123C A17C7E4100 mov eax,[$00417e7c] 00411241 E8C654FFFF call @UStrCopy //call the unicode version of copy Project91.dpr.17: Writeln(u); 00411246 A1EC2C4100 mov eax,[$00412cec]