一个关于WideString和PByteArray的问题,请教大家.
下面是我的一段代码.
问题是这样的: 我想实现以下过程 string -> WideString -> ByteArray -> WideString -> string.
但是中间出了问题,输入的string和得到的string并不相同.
以前我是学C++的,后来改用Delphi了,但Pascal基础不好.请大家多多指教.
procedure TfmMain.btnTestClick(Sender: TObject);
var
W, R: WideString;
S: string;
P: PByteArray;
I: Integer;
begin
S := '中国人123';
I := Length(S);
P := AllocMem(I * 2);
try
W := S;
Move(W[1], P^[3], I);
SetLength(R, I);
Move(P^[3], R[1], I);
S := R;
ShowMessage(Format('[%s]', [S]);
finally
FreeMem(P);
end;
end;