Skip to content

R3V1Z3/eval-expression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

EvalExpression

screenshot

Simple expression evaluator example project for Lazarus IDE. The project includes a form with a couple text fields and a label. Users can enter math expressions in the first field and get evaluated results as they type.

Evaluations are handled through TFPExpressionParser which is bundled with Lazarus.

The bulk of the code is as simple as this:

procedure Teval.ExpressionChange(Sender: TObject);
var
  FParser: TFPExpressionParser;
  resultValue: Double;
  exp: String;
begin
  exp := Expression.Text;
  if exp = '' then exp := '0';
  FParser := TFPExpressionParser.Create(nil);
  try
    FParser.BuiltIns := [bcMath];
    FParser.Expression := exp;
    resultValue := ArgToFloat(FParser.Evaluate);
    Result.caption := resultValue.ToString();
    Result.Color := clCream;
    FParser.Free;
  except
    Result.caption := 'nil';
    Result.Color := clYellow;
    FParser.Free;
  end;
end;

Usage

Simply clone the repo and open the project in Lazarus.

About

Simple expression evaluator example project for Lazarus IDE

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages