Calculator for delphi 5.0/6.0

This is a delphi component for calculating expressions at run time, Powerful and very easy to use.

Download : http://assistsoft.com/Cal/Cal010.zip
Functions | Usage | Error message | Build in functions| Sample expressions | Order| Contact
Functions :

1. operator supported : + , - , * , /, ^ , = , ==, > , < , >= , <= ,<> , & , | , ( , )
2. support multi-line.
3. support parameter.
4. support self defined functions.
5. support variable.
6. build in ten more functions , you can expand it easily.
7. error message handling.
8. formated export the result.
9. support nested functions.

Usage:

1, Install this component.
2, drag a TCalculator onto your form.
3, Set the "Param" property if need.
4, Run the "Cal" method to calculate your expression.
5, read the calculate result from "CalResult" property.

Properties:
property ResultFormat:string;
The result format string , default is '%20.5f'.

property Param:TStringList;
The parameter list, add your variables to this parameter list.
For example: Param.Add('A=20');
or: Param.values['A'] :='20';

property CalResult:TStringList;
This property will store the calculate result.

property ErrorCode:integer;
After calling method "Cal" , if there is a error , ErrorCode will return the error code, otherwise it will return zero.

property ErrorMsg:string;
if there is a error , ErrorMsg will return the error message, otherwise it will return ''.

property ErrorLine:integer;
if there is a error , ErrorLine will return the error line.

Methods:
function Cal(Expr:string):integer;
This function will do the actual calculate. the multi-line expression can be seperated by "return" (#13),this function will calculate the expression line by line.

Events:
OnFunction:TOnFunction;
TOnFunction = procedure (Sender:TObject; fName:string; Param:array of double; var R:double; var Handled:boolean) of object;

This is the self defined function callback event.
Sender : the Sender Object
fName : the function name
Param : the parameter array of this function
R : return the function result.
Handled: if you handled this function , please set this variable to true.

Error Messages:

301:Parameter count error.
302:Undefined Function : FunctinName
303:Undefined variable : VariableName
304:XX is not a Number
305:() not matching
306:division by zero

Build in functions:

sin , cos, ln , log , logN , sqrt , sum , avg , min , max , norm , variance

Sample expressions:

------------------------
How to use variable:

 B= 20
 A= (30 + B) ^ 2 /2

 the result will be

 B=   20.00000
 A= 1250.00000

------------------------
Nested build in functions:

 sum(10,sin(pi/2),sum(1,2,3,4))

 parameter : pi=3.1415926

 the result will be

 21.00

------------------------
Condition expression

 A = sum(Price1,Price2)
 B = (A > 10) * Price1 + (A<=10) *Price2

 parameter: Price1 = 5
            Price2 = 1

 the result will be

 A=   6.00000
 B=   1.00000



 parameter : Price1=6
             Price2=5

 the result will be

 A=  11.00000
 B=   6.00000

---------------------------
Self defined functions:

Salary1=GetSalary(1)
Salary2=GetSalary(2)
Salary3=GetSalary(3)
Sum=Salary1+Salary2+Salary3

 the result will be

Salary1=   5500.00
Salary2=   6000.00
Salary3=   4500.00
Sum=  16000.00

Prices & Order

TCalculator (full source code included) $29
Order Page

Contact

HomePage:
http://assistsoft.com/cal
EMail: nohacksupport@assistsoft.com (remove the nohack when you send mail)