16,747
社区成员




高版本中,需要怎么调整?如下转换函数,在两个版本的Delphi中,返回的数据不一致;
并且,高版本中按照如下这两种AnsiChar和chr ,打印后获取的值也不一致;
LogToFile(IntToStr(I)+'=='+AnsiChar(StrToInt('0x' + Copy(Value, I, 2))), True);
LogToFile(IntToStr(I)+'++'+Chr(StrToInt('0x' + Copy(Value, I, 2))), True);
比如 '0xE2' 前者是?,后者是a
==?
++a
--0xE2
再比如:'0xC9' 前者返回是?,后者是é
==?
++é
--0xC9
这样升级Delphi版本后,就不能通用了;那么,这种情况,高版本中如何替换Chr函数,能够实现一致的返回值呢?还是说无解?
具体的函数如下:
function HexToStr(Value: string): string;
var
I: Integer;
begin
Result := '';
LogToFile('=='+IntToStr(Length(Value)), True);
for I := 1 to Length(Value) do
begin
if ((I mod 2) = 1) then
begin
LogToFile(IntToStr(I)+'=='+AnsiChar(StrToInt('0x' + Copy(Value, I, 2))), True);
LogToFile(IntToStr(I)+'++'+Chr(StrToInt('0x' + Copy(Value, I, 2))), True);
// LogToFile(IntToStr(I)+'--'+'0x' + Copy(Value, I, 2), True);
Result := Result + Chr(StrToInt('0x' + Copy(Value, I, 2)));
end;
end;
LogToFile('=='+Result, True);
end;