關於DELPHI陣列,指標,字串轉換的例子:
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陣列,指標,字串轉換的例子:
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;