Hello --
I am using TfpExpressionParser in a small demo program and cannot figure out how to trap exceptions the parser generates. Below is the code I've tried. I think I am misunderstanding how 'try .. except' statements work.
The parser is initialized by:
Parser := TFPExpressionParser.Create(self);
Parser.BuiltIns := [bcMath];
in the FormActivate procedure and it evaluates with:
procedure TMain.btnCalcClick(Sender: TObject);
var
ans: Boolean;
begin
try
Parser.Expression:=edtInput.Text;
ans:=Parser.Evaluate.ResBoolean;
except
On E: Exception do begin
ShowMessage('Error: '+E.Classname +#10#13+ E.Message);
//Execute Error correction steps
end;
end;
if ans then edtResult.Text:='True'
else edtResult.Text:='False';
end;
If edtInput.Text is "2 + * 3 = 5", the parser throws the error "EExprParser, Unknown token at pos 5". The code never enters the "except" section. How do I get the except section to run when an exception occurs?
Lazarus 1.8.4, FPC 3.04
Thanks
Bert