home *** CD-ROM | disk | FTP | other *** search
- { Cool Calculator 1.3,
-
- Copyright (c) 1995, Desmond F. Nolan, All Rights Reserved. }
-
- unit Ccalcdlg;
-
- { This program uses tabs at every 3 spaces. }
-
- {BACKGROUND: The Cool Calculator Version 1.3 program is part of
- the Pie Right family of software products produced by abc Systems. As
- of August 20, 95 the Pie Right Software Family consists of a number of
- small and relatively simple Delphi programs which we have been using
- to develop our Delphi skills. All versions of these programs are
- currently being made available for use by individuals and organizations
- without charge through the Borland Delphi forums on CompuServe.
-
- Cool Calculator 1.2 is a simple business calculator in which you
- can either type your expressions (including use of parentheses)
- are build them by clicking on a collection of buttons (1, 2, 3,
- 4, 5, 6, 7, 8, 9, 0, (, ), *, +, -, /, =). Pysically it is a simple
- interface (Delphi Form) to an expression evaluation engine
- originally written by James L. Dean in 1985, and overhauled and
- enhanced by David J. Firth in 1991.
-
- We have not surfaced all the functionality of David's program, but
- it is not difficult to do so, if you are so inclined. Things left
- unsurfaced are: ABS, ARCTAN, COS, EXP, LN, SQR, SQRT, and PI
- functions, along with the ability to use variables.
-
- The code for David J. Wirth's version of the evaluation engine and
- his additional RPN evaluation engine can be found on the Delphi
- forum on CompuServe in the file called EEV10.ZIP. In extending the
- Cool Calculator are using the calculation engine in your programs
- you will want to download that file. We have included some of
- David's information about his program below.
-
- We are also the producers of Yowser Browser Version 1.2 and
- just in case you didn't know, Yowser Browser is a program
- which allows you browse long descriptions of all files uploaded to
- CompuServe's Delphi forum (that is uploaded prior to the last data
- update of Yowser Browser). Yowser Browser allows you set various
- filters to focus in on datasets, sort by different keys, search
- across all libraries, and the actual text of file descriptions
- themselves (i.e. you are not restricted to just searching file titles
- and keywords). Data for Yowser Browser is gathered by a program
- called Import File Descriptions Version 1.2.
-
- We are currently amusing ourselves with a statistical program that will
- return variance, standard variance, average deviation, and some other
- statistics for table based data. This done, we will probably move on to
- other math programs and would appreciate hearing from others who are
- doing similar, and more importantly those who might like to exchange code.
- It may seem strange to be doing these things in Delphi/Pascal instead of
- C, C++, or FORTRAN, and probable is, but now and again we get upset
- that we are not putting our years of math, statistical and econometrical
- training to use and break done and practice some of our old lessons in
- whatever language we are currently working with.
-
- ********************************************************
-
- IF YOU HAVE ANY QUESTIONS ASK:
-
- Des Nolan, Principal Consultant
- Advanced Business Continuity Systems, Inc.
- d/b/a abc Systems
- Bridgeport, CT
- Compuserve: 73150,350
- Phone: (203) 373-1021
-
- "We are available for consulting assignments<g>."
-
- ********************************************************
-
- DISCLAIMER: This program is supplied free for individual use and is
- supplied as-is. I Des Nolan and abc Systems explicitly disclaims
- all responsibility for its use or misuse by anybody. Also, no
- warranties whatsoever are offered for this program, including any
- form of merchanability. Permission to use this program is given
- to individuals and companies only if they are willing to assume
- ALL risk for its use.
-
- This program may not be sold are incorporated in another product
- or service without the prior permission of the author.
-
- ***************************************************
-
- "Thanks for downloading this program and taking a look."
-
- ***************************************************
- }
-
-
- {===========================================================
- Interface
- ===========================================================}
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, InFix, StdCtrls, ExtCtrls, IniFiles, AboutDlg;
-
- type
- TdlgCalculator = class(TForm)
- edtExpression: TEdit;
- btn3: TButton;
- lblResult: TLabel;
- btn1: TButton;
- btn4: TButton;
- btn7: TButton;
- btn2: TButton;
- btn5: TButton;
- btn8: TButton;
- btn9: TButton;
- btn6: TButton;
- btn0: TButton;
- btnDecimal: TButton;
- btnEquals: TButton;
- btnDivide: TButton;
- btnMultiply: TButton;
- btnMinus: TButton;
- btnPlus: TButton;
- btnExampleA: TButton;
- btnClear: TButton;
- btnLeftBracket: TButton;
- btnRightBracket: TButton;
- btnBackSpace: TButton;
- btnEnter: TButton;
- shpLine: TShape;
- btnAbout: TButton;
- lblEqualSign: TLabel;
- procedure btnExampleAClick(Sender: TObject);
- procedure btn1Click(Sender: TObject);
- procedure btnEqualsClick(Sender: TObject);
- procedure btnClearClick(Sender: TObject);
- procedure btnBackSpaceClick(Sender: TObject);
- procedure edtExpressionKeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure btnAboutClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure EvaluateExp(Const MyExpr : string);
- procedure addChar(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- real = extended; { Used for compatibility with evaluation engine. }
-
- var
- dlgCalculator: TdlgCalculator;
- vbFormatResult : Boolean;
- vlWidth, vlNumOfDecs : LongInt;
-
- {===========================================================
- Implementation
- ===========================================================}
- implementation
-
- {$R *.DFM}
-
- {------------------------------------------------------
- Call function from evaluation engine and display result.
- ------------------------------------------------------}
- procedure TdlgCalculator.EvaluateExp(Const MyExpr : string);
- var
- MyErr : Byte;
- MyAddr : String[20];
- vsResult : String;
- MyResult : Real;
- vlPadNumber : LongInt;
- begin
- MyErr := 0;
- MyResult := 0.0;
- InFix.RawCalculate(MyExpr, MyResult, MyErr);
- if vbFormatResult then
- begin
- Str(MyResult:vlWidth:vlNumOfDecs, vsResult);
- lblResult.Caption := vsResult;
- end
- else
- lblResult.Caption := FloatToStr(MyResult);
- end;
-
- {------------------------------------------------------
- Add button label to expression field.
- ------------------------------------------------------}
- procedure TdlgCalculator.addChar(Sender: TObject);
- var
- btn : TButton;
- begin
- btn := TButton(Sender);
- edtExpression.Text := edtExpression.Text + btn.Caption;
- end;
-
- {-------------------------------------------------------
- User clicked one of the calculators std buttons call the
- method that adds the same character as the caption of
- the button to the edit field for the expression.
- -------------------------------------------------------}
- procedure TdlgCalculator.btn1Click(Sender: TObject);
- begin
- addChar(Sender);
- end;
-
- {-------------------------------------------------------
- "=" button was clicked so evaluate expression.
- -------------------------------------------------------}
- procedure TdlgCalculator.btnEqualsClick(Sender: TObject);
- begin
- EvaluateExp(edtExpression.Text);
- end;
-
- {-------------------------------------------------------
- "Clear" button was clicked so erase expression & result.
- -------------------------------------------------------}
- procedure TdlgCalculator.btnClearClick(Sender: TObject);
- begin
- edtExpression.Clear;
- lblResult.Caption := '';
- end;
-
- {-------------------------------------------------------
- "Backspace" button was erase last character, (actually
- the expression is redisplayed without the last character).
- -------------------------------------------------------}
- procedure TdlgCalculator.btnBackSpaceClick(Sender: TObject);
- begin
- edtExpression.Text := copy(edtExpression.Text, 1, length(edtExpression.Text) -1);
- end;
-
- {-------------------------------------------------------
- "Example A" button was clicked so insert sample expression
- along with displaying result after evaulating it.
- -------------------------------------------------------}
- procedure TdlgCalculator.btnExampleAClick(Sender: TObject);
- begin
- edtExpression.Text := '((10*10)-50)/10';
- EvaluateExp(edtExpression.Text);
- end;
-
- {-------------------------------------------------------
- "Print" button was clicked so print expression & result.
- -------------------------------------------------------}
- {-------------------------------------------------------
- If "Enter" key is pressed while edit field has focus
- evaluate the current expression and show the result.
- -------------------------------------------------------}
- procedure TdlgCalculator.edtExpressionKeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if key = VK_Return then
- EvaluateExp(edtExpression.Text);
- end;
-
- procedure TdlgCalculator.btnAboutClick(Sender: TObject);
- begin
- dlgAboutBox := TdlgAboutBox.Create(Self);
- dlgAboutBox.ShowModal;
- dlgAboutBox.Free;
- end;
-
- procedure TdlgCalculator.FormCreate(Sender: TObject);
- var
- Ini : TIniFile;
- begin
- Ini := TIniFile.Create('CoolCalc.INI');
- vbFormatResult := Ini.readBool('Calculator Options', 'Format Result', True);
- vlWidth := Ini.readInteger('Calculator Options', 'Width', 1);
- vlNumOfDecs := Ini.readInteger('Calculator Options', 'Number Of Decimals', 2);
- Ini.Free;
- end;
-
- end.
-