source: branches/textos/Apps/Calculator/UCalculator.pas

Last change on this file was 53, checked in by chronos, 12 months ago
  • Added: Experimental textos computer.
File size: 1.1 KB
Line 
1unit UCalculator;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, UApp;
9
10type
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
25implementation
26
27{ TAppCalculator }
28
29procedure TAppCalculator.OnStart;
30begin
31 Api.OutputText('Calcualtor 1.0' + LineEnding);
32end;
33
34procedure TAppCalculator.OnTerminate;
35begin
36 Api.OutputText('Bye' + LineEnding);
37end;
38
39function TAppCalculator.Evaluate(Text: string): string;
40begin
41 if Text = '1+1' then Result := '=2'
42 else Result := 'Error';
43end;
44
45procedure TAppCalculator.OnInputText;
46var
47 Text: string;
48begin
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;
56end;
57
58constructor TAppCalculator.Create;
59begin
60 inherited;
61 Name := 'Calculator';
62end;
63
64end.
65
Note: See TracBrowser for help on using the repository browser.