翻java成delphi,delphi7下有一样的编码dcu么?
- Java code
String s = new String(org.apache.commons.codec.binary.Hex.encodeHex(byte[] b));
[解决办法]
代码不是我写的,LockBox的LbUtils下面带的
- Delphi(Pascal) code
{ -------------------------------------- }function BufferToHex(const Buf; BufSize : Cardinal) : string;var I : LongInt;begin Result := ''; for I := 0 to BufSize - 1 do Result := Result + IntToHex(TByteArray(Buf)[I], 2); {!!.01}end;{ -------------------------------------- }function HexToBuffer(const Hex : string; var Buf; BufSize : Cardinal) : Boolean;var i, C : Integer; Str : string; Count : Integer;begin Result := False; Str := ''; for i := 1 to Length(Hex) do if Upcase(Hex[i]) in ['0'..'9', 'A'..'F'] then Str := Str + Hex[i]; FillChar(Buf, BufSize, #0); Count := Min(Length(Hex), BufSize); for i := 0 to Count - 1 do begin Val('$' + Copy(Str, (i shl 1) + 1, 2), TByteArray(Buf)[i], C); {!!.01} if (C <> 0) then Exit; end; Result := True;end;
[解决办法]
上面的定义 TByteArray = array[0..32767] of Byte;