function HexToStr(const S: String): String;
var
i: Integer;
t: Byte;
begin
SetLength(Result, Length(S) div 2);
FillChar(PChar(Result)^, Length(Result), 0);
for i := 1 to Length(S) div 2 * 2 do
begin
if (S[i] >= 'a') and (S[i] <= 'z') then
t := Ord(S[i]) - Ord('a') + 10
else if (S[i] >= 'A') and (S[i] <= 'Z') then
t := Ord(S[i]) - Ord('A') + 10
else if (S[i] >= '0') and (S[i] <= '9') then
t := Ord(S[i]) - Ord('0')
else
t := 0;
if i mod 2 <> 0 then t := t shl 4; Byte(Result[(i + 1) div 2]) :=Byte(Result[(i + 1) div 2]) or Byte(t);
//上面这行代码为什么可以这么赋值,在delphi7下可以编译,在delphi2010中无法编译 ,求解。
end;
end;
var
i: Integer;
t: Byte;
begin
SetLength(Result, Length(S) div 2);
FillChar(PChar(Result)^, Length(Result), 0);
for i := 1 to Length(S) div 2 * 2 do
begin
if (S[i] >= 'a') and (S[i] <= 'z') then
t := Ord(S[i]) - Ord('a') + 10
else if (S[i] >= 'A') and (S[i] <= 'Z') then
t := Ord(S[i]) - Ord('A') + 10
else if (S[i] >= '0') and (S[i] <= '9') then
t := Ord(S[i]) - Ord('0')
else
t := 0;
if i mod 2 <> 0 then t := t shl 4; Byte(Result[(i + 1) div 2]) :=Byte(Result[(i + 1) div 2]) or Byte(t);
//上面这行代码为什么可以这么赋值,在delphi7下可以编译,在delphi2010中无法编译 ,求解。
end;
end;
Result[(i + 1) div 2] := Chr(Byte(Result[(i + 1) div 2]) or Byte(t));
该改为:
Result[(i + 1) div 2] := chr( Byte(Result[(i + 1) div 2]) or Byte(t) );
function HexToStr(const S: ansiString): ansiString;
mov byte ptr result[(i+1) div 2]),byte ptr[右边],
那个Byte()只是用来指定传输大小的,和byte ptr一个道理