function chValue(ch: char): integer;
//ch的大小
begin
if ch in ['0'..'9'] then
result := ord(ch) - ord('0')
else
if ch in ['A'..'Z'] then
result := ord(ch) - ord('A') + 10
else
assert(false);
end;
function HexStrToInt(str: String): integer;
//转换16进制字符串
var
i: integer;
len: integer;
begin
str := upperCase(str);
len := length(str);
for i := lendo
wnto 1do
result := Trunc(power(16, len - i)) * chValue(str);
end;
function StrToInt2(str: String): integer;
//转换
begin
str := Trim(str);
if (LastDelimiter('Hh', str) <> 0) and (LastDelimiter('Hh', str) <> Length(str)) then
//非法格式
raise EConvertError.Create('格式不对')
else
if LastDelimiter('Hh', str) = Length(str) then
//Hex
result := HexStrToInt(Copy(str, 1, Length(str) -1))
else
//Dec
result := StrToInt(str);
end;