A simple (and understandable) example:
(It makes a single operation with 2 operands and 1 operator)
var
S, Arg1, Arg2, Op :string;
Index :byte;
Res :integer;
begin
S := Edit1.Text;
Arg1 := '';
Arg2 := '';
Op := '';
Index := 1;
while S[Index] in ['0'..'9'] do
begin
Arg1 := Arg1 + S[Index];
Inc(Index);
end;
while S[Index] = ' ' do
Inc(Index);
if S[Index] in ['+','-','*','/'] then
begin
op := S[Index];
Inc(Index);
end
else
begin
ShowMessage('Operator expected at position ' + IntToStr(Index));
Edit1.SetFocus;
Edit1.SelStart := Index -1;
Edit1.SelLength := 1;
Exit;
end;
while S[Index] = ' ' do
Inc(Index);
while S[Index] in ['0'..'9'] do
begin
Arg2 := Arg2 + S[Index];
Inc(Index);
end;
case op[1] of
'+': begin
Res := StrToInt(Arg1) + StrToInt(Arg2);
ShowMessage(IntToStr(Res));
end;
'-':begin
Res := StrToInt(Arg1) - StrToInt(Arg2);
ShowMessage(IntToStr(Res));
end;
'*':begin
Res := StrToInt(Arg1) * StrToInt(Arg2);
ShowMessage(IntToStr(Res));
end;
'/':begin
Res := StrToInt(Arg1) div StrToInt(Arg2);
ShowMessage(IntToStr(Res));
end;
end;
end;