-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuConstantGroup.pas
More file actions
99 lines (81 loc) · 2.13 KB
/
uConstantGroup.pas
File metadata and controls
99 lines (81 loc) · 2.13 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
unit uConstantGroup;
interface
uses
System.SysUtils,
uParserValue, uTextProc;
type
// Íåñ÷èòàåìîå çíà÷åíèå, ïåðåìåííàÿ èëè êîíñòàíòà
TConstantValue = class(TValue)
public
constructor Create(const AValue: String); reintroduce; virtual;
end;
TVariable = class(TConstantValue)
strict private
FPlacedValue: Double;
FPlaced: Boolean;
FValueStack: TValueStack;
function GetName: string;
procedure PlaceValue(const AValue: Double);// Ïðîñòî âûäàåò Text
public
property Name: string read GetName; // Íàçâàíèå ýòî ïî ñóòè òåêñò ïåðåìåííîé
property ValueStack: TValueStack read FValueStack write FValueStack;
// procedure PlaceValue(const AValue: Double);
function Value: Double; override;
constructor Create(const AValue: String); override;
end;
TDouble = class(TConstantValue)
public
function Value: Double; override;
end;
implementation
{ TVariable }
constructor TVariable.Create(const AValue: String);
begin
inherited;
Text := AValue;
FPlaced := False;
Self.BoundLeft := 1;
Self.BoundRight := Length(AValue)
end;
function TVariable.GetName: string;
begin
Result := Self.Text;
end;
procedure TVariable.PlaceValue(const AValue: Double);
begin
FPlaced := True;
FPlacedValue := AValue;
end;
function TVariable.Value: Double;
begin
if FValueStack = Nil then
raise Exception.Create('Íà çàäàí ñòåê çíà÷åíèé äëÿ ìàòåìàòè÷åñêîãî âûðàæåíèÿ.');
if FValueStack.IsHere(Name) then
begin
Result := FValueStack[Name];
end else
raise Exception.Create('Íà çàäàíî çíà÷åíèå ïåðåìåííîé «' + Name + '»');
{ Âàðèàíò êîäà äëÿ äðóãîé àðõèòåêòóðû. Íî îí íå íóæåí.
if FPlaced then
Result := FPlacedValue
else
raise Exception.Create('Íà çàäàíî çíà÷åíèå ïåðåìåííîé «' + Name + '»');}
end;
{ TDouble }
function TDouble.Value: Double;
var
vA: Double;
vErr: Integer;
begin
Val(Text, vA, vErr);
if vErr = 0 then
Result := vA
else
raise Exception.Create('Îøèáêà êîíñòàíòîâîãî çíà÷åíèÿ, íåâîçìîæíî ïåðåâåñòè â ÷èñëî ñ ïëàâàþùåé òî÷êîé «' + Text + '»');
end;
{ TConstantValue }
constructor TConstantValue.Create(const AValue: String);
begin
Text := AValue;
end;
end.