var
aa: array [0..5] of Char;
bb:Pointer;
cc:string;
dd:PChar;
procedure TForm1.Button1Click(Sender: TObject);
begin
dd:=‘abcdef‘;
//以下是pchar内容转数组
FillChar(aa,length(dd),#0);
Move(dd^,aa,SizeOf(aa));
//以下是数组传递到指针
bb:=GetMemory(SizeOf(aa));
Move(aa,bb^,SizeOf(aa));
//以下是指针内容传递给字符串
SetLength(cc,SizeOf(aa));
Move(bb^,cc[1],SizeOf(aa));
FreeMemory(bb);//这个是释放内存
//以下是数组转pchar
dd:=‘‘;
dd:=PChar(@aa);
MessageBox(0,PChar(‘cc: ‘+cc),PChar(‘dd: ‘+dd),0);
end;
关于DELPHI数组,指针,字符串转换的例子!(转),布布扣,bubuko.com
时间: 2024-10-10 02:09:15