source: branches/topdown/Apps/AppCalc.pas

Last change on this file was 37, checked in by chronos, 17 months ago
  • Modified: Simplified unit names.
File size: 1.5 KB
Line 
1unit AppCalc;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, OsSystem;
7
8type
9 TOperation = (opNone, opAdd, opMultiply);
10
11 { TFormCalculator }
12
13 TFormCalculator = class(TFormTask)
14 ButtonCompute: TButton;
15 ButtonAdd: TButton;
16 ButtonMultiply: TButton;
17 EditInput: TEdit;
18 procedure ButtonAddClick(Sender: TObject);
19 procedure ButtonComputeClick(Sender: TObject);
20 procedure ButtonMultiplyClick(Sender: TObject);
21 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
22 private
23
24 public
25 ResultValue: Integer;
26 LastOp: TOperation;
27 procedure Calculate;
28 end;
29
30
31implementation
32
33{$R *.lfm}
34
35{ TFormCalculator }
36
37procedure TFormCalculator.ButtonAddClick(Sender: TObject);
38begin
39 Calculate;
40 LastOp := opAdd;
41 EditInput.SetFocus;
42 EditInput.SelectAll;
43end;
44
45procedure TFormCalculator.ButtonComputeClick(Sender: TObject);
46begin
47 Calculate;
48 EditInput.SetFocus;
49 EditInput.SelectAll;
50end;
51
52procedure TFormCalculator.ButtonMultiplyClick(Sender: TObject);
53begin
54 Calculate;
55 LastOp := opMultiply;
56 EditInput.SetFocus;
57 EditInput.SelectAll;
58end;
59
60procedure TFormCalculator.FormClose(Sender: TObject;
61 var CloseAction: TCloseAction);
62begin
63 Terminate;
64end;
65
66procedure TFormCalculator.Calculate;
67begin
68 if LastOp = opAdd then begin
69 ResultValue := ResultValue + StrToInt(EditInput.Text);
70 end else
71 if LastOp = opMultiply then begin
72 ResultValue := ResultValue * StrToInt(EditInput.Text);
73 end;
74 EditInput.Text := IntToStr(ResultValue);
75end;
76
77end.
78
Note: See TracBrowser for help on using the repository browser.