谢谢大家的帮助,我找到解决办法,我发放出来吧,感谢代码作者,第一个是发送前string转HEX,第二个是收到hex转string!每人25分,大家没意见吧....................
function HexStrToStr(const S: string): string;
//16进制字符串转换成字符串
var
t: Integer;
ts: string;
M, Code: Integer;
begin
t := 1;
Result := '';
while t <= Length(S) do
begin //xlh 2006.10.21
while (t <= Length(S)) and (not (S[t] in ['0'..'9', 'A'..'F',
'a'..'f'])) do
Inc(t);
if (t + 1 > Length(S)) or (not (S[t + 1] in ['0'..'9', 'A'..'F',
'a'..'f'])) then
ts := '$' + S[t]
else
ts := '$' + S[t] + S[t + 1];
Val(ts, M, Code);
if Code = 0 then
Result := Result + Chr(M);
Inc(t, 2);
end;
end;
function StrToHexStr(const S: string): string;
//字符串转换成16进制字符串
var
I: Integer;
begin
for I := 1 to Length(S) do
begin
if I = 1 then
Result := IntToHex(Ord(S[1]), 2)
else
Result := Result + ' ' + IntToHex(Ord(S), 2);
end;
//ShowMessage(inttostr(I));
end;