-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUMain.pas
60 lines (49 loc) · 1.49 KB
/
UMain.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
unit UMain;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Edit, FMX.Controls.Presentation, UICalculation;
type
TfrmMain = class(TForm)
lbl1: TLabel;
lbl2: TLabel;
lbl3: TLabel;
lbl4: TLabel;
lblResult: TLabel;
edtVal1: TEdit;
edtVal2: TEdit;
swtchMultiplicationType: TSwitch;
btnAddition: TButton;
btnMultiplication: TButton;
procedure ExecuteAddition(aCaller: TObject);
procedure ExecuteMultiplication(aCaller: TObject);
private
procedure DisplayResult(aCalculation: ICalculation);
end;
var
frmMain: TfrmMain;
implementation
uses
UTCalculationFactory;
{$R *.fmx}
procedure TfrmMain.DisplayResult(aCalculation: ICalculation);
begin
if not Assigned(aCalculation) then
raise Exception.Create('Undefined calculation method');
lblResult.Text := aCalculation.Calculation(edtVal1.Text.ToInteger, edtVal2.Text.ToInteger).ToString;
end;
procedure TfrmMain.ExecuteAddition(aCaller: TObject);
begin
DisplayResult(TCalculationFactory.CalculationMethod(cAdd));
end;
procedure TfrmMain.ExecuteMultiplication(aCaller: TObject);
var
CalcType: TCalculationType;
begin
CalcType := cMulti;
if swtchMultiplicationType.IsChecked then
CalcType := cMultiPerAdd;
DisplayResult(TCalculationFactory.CalculationMethod(CalcType));
end;
end.