+ -
当前位置:首页 → 问答吧 → 有关 TEncoding 再求助

有关 TEncoding 再求助

时间:2011-09-08

来源:互联网

这是原代码(delphi 2009):
Delphi(Pascal) code

function ToHexString(s: string; encode: TEncoding): string;
var TmpStr: string;
  ByteAy: Tbytes;
  tmpByte: Byte;
begin
  ByteAy := encode.GetBytes(s);
  TmpStr := '';
  for tmpByte in ByteAy do
  TmpStr := Format('%s%.2x', [tmpstr, tmpbyte]);
  Result := TmpStr;
end;




转换成delphi7:
Delphi(Pascal) code

function ToHexString(s: string; encode: Integer): string;
var
  len:Integer;
  w:WideString;
  u:UTF8String;
begin
  Result := '';
  if encode=1 then //Unicode
  begin
    w:=s;
    Len := Length(w)*2;
    SetLength(Result, Len shl 1);
    BinToHex(PChar(w), PChar(Result), Len);
  end else
  if encode=2 then //UTF8
  begin
    u:=AnsiToUTF8(s);
    Len := Length(u);
    SetLength(Result, Len shl 1);
    BinToHex(PChar(u), PChar(Result), Len);
  end;
end;



可是转换后的代码仅支持ansi编码,如果要支持unicode,即
Delphi(Pascal) code

function ToHexString(s: widestring; encode: Integer): string;
begin

end;


该怎么做?在delphi7下BinToHex不支持unicode,tnt组件也没有该函数

作者: diystar2   发布时间: 2011-09-08

原帖:
http://topic.csdn.net/u/20100328/12/35be70eb-bc75-4820-aef5-b2a5e246ee6b.html

作者: diystar2   发布时间: 2011-09-08

热门下载

更多