function ParseStr(Value:
String): Double;
function GetKlammerZuPos(SubValue: PChar): Integer;
var KlammerCount: Integer;
begin
KlammerCount := 1;
for Result := 0
{0 ist 1. Klammer auf} to Length(SubValue) -1
do
begin // for
if (SubValue + Result)[0] = '
('
THEN inc(KlammerCount);
if (SubValue + Result)[0] = '
)'
THEN dec(KlammerCount);
if KlammerCount = 0
THEN Exit;
end;
// for
Raise Exception.Create('
Die Klammer wurd nicht wieder geschlossen: '+SubValue);
end;
Var iPos, jPos: Integer;
modValue :
String;
begin
modValue := Value;
WHILE Pos('
(',modValue) > 0
DO
BEGIN
iPos := Pos('
(',modValue);
jPos := GetKlammerZuPos(Pchar(modValue) + iPos);
modValue := Copy(modValue,0,iPos-1) +
FloatToStr(ParseStr(Copy(modValue,iPos+1,jPos))) +
Copy(modValue,iPos+jPos+2,9999);
END;
if (Pos('
-',modValue) > 0)
OR
(Pos('
+',modValue) > 0)
then
begin // strichrechnung
iPos := Pos('
-',modValue);
IF iPos <> 0
THEN
BEGIN
Result := ParseStr(Copy(modValue,0,iPos-1)) - ParseStr(Copy(modValue,iPos+1,9999));
Exit;
END;
iPos := Pos('
+',modValue);
IF iPos <> 0
THEN
BEGIN
Result := ParseStr(Copy(modValue,0,iPos-1)) + ParseStr(Copy(modValue,iPos+1,9999));
Exit;
END;
Raise Exception.Create('
Programmierfehler !');
end;
// strichrechnung
if (Pos('
/',modValue) > 0)
OR
(Pos('
*',modValue) > 0)
then
begin // punktrechnung
iPos := Pos('
/',modValue);
IF iPos <> 0
THEN
BEGIN
Result := ParseStr(Copy(modValue,0,iPos-1)) / ParseStr(Copy(modValue,iPos+1,9999));
Exit;
END;
iPos := Pos('
*',modValue);
IF iPos <> 0
THEN
BEGIN
Result := ParseStr(Copy(modValue,0,iPos-1)) * ParseStr(Copy(modValue,iPos+1,9999));
Exit;
END;
Raise Exception.Create('
Programmierfehler !');
end;
// punktrechnung
// keine Rechnung mehr zum Auflösen gewesen
Result := StrToFloat(modValue);
end;