Line | |
---|
1 | unit AppCalc;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, OsSystem;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
31 | implementation
|
---|
32 |
|
---|
33 | {$R *.lfm}
|
---|
34 |
|
---|
35 | { TFormCalculator }
|
---|
36 |
|
---|
37 | procedure TFormCalculator.ButtonAddClick(Sender: TObject);
|
---|
38 | begin
|
---|
39 | Calculate;
|
---|
40 | LastOp := opAdd;
|
---|
41 | EditInput.SetFocus;
|
---|
42 | EditInput.SelectAll;
|
---|
43 | end;
|
---|
44 |
|
---|
45 | procedure TFormCalculator.ButtonComputeClick(Sender: TObject);
|
---|
46 | begin
|
---|
47 | Calculate;
|
---|
48 | EditInput.SetFocus;
|
---|
49 | EditInput.SelectAll;
|
---|
50 | end;
|
---|
51 |
|
---|
52 | procedure TFormCalculator.ButtonMultiplyClick(Sender: TObject);
|
---|
53 | begin
|
---|
54 | Calculate;
|
---|
55 | LastOp := opMultiply;
|
---|
56 | EditInput.SetFocus;
|
---|
57 | EditInput.SelectAll;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | procedure TFormCalculator.FormClose(Sender: TObject;
|
---|
61 | var CloseAction: TCloseAction);
|
---|
62 | begin
|
---|
63 | Terminate;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | procedure TFormCalculator.Calculate;
|
---|
67 | begin
|
---|
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);
|
---|
75 | end;
|
---|
76 |
|
---|
77 | end.
|
---|
78 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.