...
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
fpexprpars;
{ TForm1 }
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
s, after: String;
FParser: TFPExpressionParser;
resultValue: integer;
begin
s:= '150 20 100 10 1';
after := StringReplace(s, ' ', '+', [rfReplaceAll, rfIgnoreCase]);
FParser := TFPExpressionParser.Create(nil);
try
FParser.BuiltIns := [bcMath];
FParser.Expression := after;
resultValue := FParser.Evaluate.ResInteger;
Memo1.Lines.Add( FParser.Expression + ' = ' + IntToStr(resultValue));
finally
FParser.Free;
end;
end;