type
PByteArr = ^TByteArr;
TByteArr = array of Byte;
function ByteArrayToWideString(Data: TByteArr): WideString;
var
Len: Integer;
begin
Len := Length(Data);
SetLength(Result, Len shr 1);
Move(Data[0], Pointer(Result)^, Len);
end;
function WideStringToByteArray(const Data: WideString): TByteArr;
var
Len: Integer;
begin
Len := Length(Data);
SetLength(Result, Len shl 1);
Move(Pointer(Data)^, Result[0], Len shl 1);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
W: WideString;
D: TByteArr;
begin
W := 'abc汉字';
D := WideStringToByteArray(W);
Caption := ByteArrayToWideString(D);
end;