Line | |
---|
1 | unit UCalculator;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, UApp;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TAppCalculator }
|
---|
13 |
|
---|
14 | TAppCalculator = class(TApp)
|
---|
15 | private
|
---|
16 | Line: string;
|
---|
17 | public
|
---|
18 | procedure OnStart; override;
|
---|
19 | procedure OnTerminate; override;
|
---|
20 | function Evaluate(Text: string): string;
|
---|
21 | procedure OnInputText; override;
|
---|
22 | constructor Create; override;
|
---|
23 | end;
|
---|
24 |
|
---|
25 | implementation
|
---|
26 |
|
---|
27 | { TAppCalculator }
|
---|
28 |
|
---|
29 | procedure TAppCalculator.OnStart;
|
---|
30 | begin
|
---|
31 | Api.OutputText('Calcualtor 1.0' + LineEnding);
|
---|
32 | end;
|
---|
33 |
|
---|
34 | procedure TAppCalculator.OnTerminate;
|
---|
35 | begin
|
---|
36 | Api.OutputText('Bye' + LineEnding);
|
---|
37 | end;
|
---|
38 |
|
---|
39 | function TAppCalculator.Evaluate(Text: string): string;
|
---|
40 | begin
|
---|
41 | if Text = '1+1' then Result := '=2'
|
---|
42 | else Result := 'Error';
|
---|
43 | end;
|
---|
44 |
|
---|
45 | procedure TAppCalculator.OnInputText;
|
---|
46 | var
|
---|
47 | Text: string;
|
---|
48 | begin
|
---|
49 | Text := Api.InputText;
|
---|
50 | Api.OutputText(Text);
|
---|
51 | if Text[1] = #13 then begin
|
---|
52 | if Line = 'exit' then Terminate
|
---|
53 | else Api.OutputText(LineEnding + Evaluate(Line) + LineEnding);
|
---|
54 | Line := '';
|
---|
55 | end else Line := Line + Text;
|
---|
56 | end;
|
---|
57 |
|
---|
58 | constructor TAppCalculator.Create;
|
---|
59 | begin
|
---|
60 | inherited;
|
---|
61 | Name := 'Calculator';
|
---|
62 | end;
|
---|
63 |
|
---|
64 | end.
|
---|
65 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.