function BytesOf(const Val: AnsiString): TBytes;
var
Len: Integer;
begin
Len := Length(Val);
SetLength(Result, Len);
Move(Val[1], Result[0], Len);
end;
function StringOf(const buf:TBytes): AnsiString;
begin
SetLength(Result, Length(buf));
CopyMemory(PAnsiChar(result), @buf[0], Length(buf));
end;
正常Delphi2009及以上Unicode版本中我们是使用TEncoding类进行处理(该方法跟JAVA,C#中完全一样)
var
AnsiKey: TBytes;
sKey:String;
AnsiKey := TEncoding.ASCII.GetBytes(Key);
或
AnsiKey := TEncoding.UTF8.GetBytes(Key);