function RomanToDec(Roman: String): LongInt;
const
Romans: Array[1..18] of String = ('I', 'V', 'X', 'L', 'C', 'D', 'M', 'IV', 'IX', 'XL',
'XC', 'IC', 'CD', 'CM', 'IM', '(M)', '[M]', '{M}');
Arabics: Array[1..18] of Integer = (1, 5, 10, 50, 100, 500, 1000, 4, 9, 40,
90, 99, 400, 900, 999, 10000, 100000, 1000000);
procedure ConvertDigit(var sText: String; var iRes: Integer; const sRom: String;
const iRab: Integer);
var iTemp: Integer;
begin
repeat
iTemp := Pos(sRom, sText);
if iTemp >= 1 then
begin
Inc(iRes, iRab);
Delete(sText, iTemp, Length(sRom));
end;
until iTemp = 0;
end;
var
iFor: Integer;
begin
Result := 0;
for iFor := 18 downto 1 do
begin
ConvertDigit(Roman, Result, Romans[iFor], Arabics[iFor]);
end;
end;