Jump to content
Sign in to follow this  
Yaron

An elegant open-source calculator for Android

Recommended Posts

I wrote a simple & elegant calculator for Android using Delphi Tokyo 10.2.3 and released the source code on GitHub:
https://github.com/bLightZP/ElegantCalculator

 

This sample demonstrates basic scalable Android UI, taking screen scale into account.

I wrote a basic string math formula parser since I couldn't find anything free that would compile for Android.

 

You can check out the compiled Elegant Calculator on the google play store:
https://play.google.com/store/apps/details?id=com.inmatrix.ElegantCalculator

 

Edited by Yaron
  • Like 1
  • Thanks 1

Share this post


Link to post

With a few tweaks you can compile and install TArtFormula @ http://artsoft.tech/works.html

 

Download @ http://artsoft.tech/download.html

It works pretty well and supports quite a bit of things.

 

 

Share this post


Link to post

I actually reviewed two other formula parser, one was strictly windows and the other I thought I could convert, but after a few hours of work with it working perfectly under windows and having odd crashes under Android, I decided to just write something simple myself.

Edited by Yaron

Share this post


Link to post

An easy way to implement formulas is to rely on FireDAC expressions.

It is very powerful (I built a simple spreadsheet-like application with very small effort!)

 

Sincerely

  • Haha 1

Share this post


Link to post

Another good expression parser is the one from LiveBindings, explained by Daniele Teti.

Not sure if that old XE2 sample still works, but it should give the basic idea.
I use the expression engine of LiveBindings for calculations in my projects, usable in runtime.

 

This is how I use it:

uses
    System.Rtti
  , System.Bindings.EvalSys
  , System.Bindings.EvalProtocol
  , System.Bindings.Evaluator
  , System.Bindings.Methods
  ;



function TTestCalculator.Evaluate(const AExpr: string) : Double;
var
  LScope: IScope;
  LCompiledExpr: ICompiledBinding;
  LResult: TValue;


begin
  Result := 0.0;

  try
      LScope := TNestedScope.Create(BasicOperators, BasicConstants);

      //add the registered methods
      LScope := TNestedScope.Create(LScope, TBindingMethodsFactory.GetMethodScope);

      LCompiledExpr := Compile(AExpr, LScope);
      LResult       := LCompiledExpr.Evaluate(LScope, nil, nil).GetValue;

      if not LResult.IsEmpty then
        Result := LResult.AsExtended;

  finally

    LCompiledExpr    := nil;
    LScope           := nil;
  end;

end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×