分类: WINDOWS
2012-09-25 10:08:08
procedure TForm1.Button2Click(Sender: TObject);
var
s:string;
p:pchar;
begin
p:='good';
s:=p; //pChar-->String 可直接赋值
//s:=strpas(p); //pChar-->String;
showmessage(s);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
s:string;
p:pchar;
begin
s:='bad';
p:=pchar(s); //String-->pChar 类型映射
showmessage(p);
end;
另外:由于String 第0个是存放字符长度的,可这么写
procedure TForm1.Button1Click(Sender: TObject);
var
s:String;
p:pchar;
begin
s:= 'new';
label2.caption:=intTostr(Length(s));{3是字符串的长度}
p:=@s[1]; //String-->PChar
showMessage(p);
end;
转自:
http://gzkhrh.blog.51cto.com/30447/155304