适用于DELPHI2007及以下版本的BytesOf和StringOf (字符串转TBtyes)
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);
本文来自博客园,作者:IT情深,转载请注明原文链接:https://www.cnblogs.com/wh445306/p/16751681.html