This is an old thread, but here is a set of operators for converting string types to TBytes and vice versa;
operator := (const a:ShortString):TBytes;inline;
begin
setlength(Result,length(a));
move(a[1],Result[0],length(a));
end;
operator := (const a:AnsiString):TBytes;inline;
begin
setlength(Result,length(a));
move(a[1],Result[0],length(a));
end;
operator := (const a:UTF8String):TBytes;inline;
begin
setlength(Result,length(a));
move(a[1],Result[0],length(a));
end;
operator := (const a:UnicodeString):TBytes;inline;
begin
setlength(Result,length(a));
move(a[1],Result[0],length(a));
end;
operator := (const a:TBytes):shortstring;inline;
begin
SetString(Result,PAnsiChar(a),length(a));
end;
operator := (const a:TBytes):AnsiString;inline;
begin
SetString(Result,PAnsiChar(a),length(a));
end;
operator := (const a:TBytes):UTF8String;inline;
begin
SetString(Result,PAnsiChar(a),length(a));
end;
{// currently has problems. When fixed, uncomment.
operator := (const a:TBytes):UnicodeString;inline;
begin
SetString(Result,PAnsiChar(a),length(a));
end;
}
It's just to remember forever they are there.
length() returns the length
in bytes for all string types.