字符串与字符串指针
function _Wide2Ansi(Achar: Pchar): PAnsiChar; var lv: Ansistring; begin lv := Ansistring(string(Achar)); Result := PAnsiChar(lv); end; function _Ansi2Wide(Achar: PAnsiChar): Pchar; var lv: string; begin lv := String(Ansistring(Achar)); Result := Pchar(lv); end;
var lansistr:AnsiString; lansichar:PAnsiChar; lstr:string; lchar:Pchar; I: Integer; begin GetMem(lansichar,100); GetMem(lchar,100); Memo1.lines.add('ansichar:'+integer(lansichar).ToString); Memo1.lines.add('char:'+integer(lchar).ToString); try lansichar:=Pansichar('天天123'); Memo1.lines.add('ansichar:'+integer(lansichar).ToString+ansistring(lansichar)); lansistr:=Ansistring(lansichar); Memo1.lines.add('ansistring:'+integer(lansichar).ToString+lansistr); lstr:=string(lansichar); Memo1.lines.add('string:'+integer(lstr).ToString+lstr); MoveMemory(lchar,Pointer(lstr),100); // MoveArray(); // for I := Low(lstr) to High(lstr) do // begin // lchar[i]:=lstr[i]; // end; // lchar:=Pchar(lstr); Memo1.lines.add('pchar:'+integer(lchar).ToString+string(lchar)); finally FreeMem(lansichar); FreeMem(lchar); end;
酒肉穿肠过
佛祖心中留
世人若学我
如同入魔道