fpc和delphi字符串和字节数组相互转换
fpc和delphi字符串和字节数组相互转换
代码照顾delphi7等低版本。
function BytesToText(const ABytes: TBytes): string; var LLen: Integer; begin LLen := Length(ABytes); {$ifdef unicode} SetLength(Result, LLen div 2); Move(ABytes[0], Result[1], LLen); {$else} SetLength(Result, LLen); Move(ABytes[0], Result[1], LLen); {$endif} end; function TextToBytes(const AText: string): TBytes; var LLen: Integer; begin LLen := Length(AText); {$ifdef unicode} SetLength(Result, LLen * 2); Move(AText[1], Result[0], LLen * 2); {$else} SetLength(Result, LLen); Move(AText[1], Result[0], LLen); {$endif} end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/18850824