ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JDesigner/uSymbolList.pas
Revision: 1.1.1.1 (vendor branch)
Committed: Mon Dec 10 19:29:13 2001 UTC (15 years ago) by hsauro
Branch: MAIN, hsauro
CVS Tags: V10, HEAD_NEW, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
no message

Line File contents
1 unit uSymbolList;
2
3 interface
4
5 Uses SysUtils, Classes, uNetUtils;
6
7 type
8 TSymbol = class (TObject)
9 Name : string;
10 value : double;
11 hasValue : boolean;
12 procedure Save (s : TStream);
13 constructor Read (s : TStream); overload;
14 constructor Create; overload;
15 constructor Create (Name : string; value : double; hasValue : boolean); overload;
16 end;
17
18 TSymbolList = class (TList)
19 private
20 protected
21 function Get (Index : integer) : TSymbol;
22 procedure Put (Index : integer; Item : TSymbol);
23 public
24 constructor Create;
25 destructor Destroy; override;
26 function Add (Item : TSymbol) : integer;
27 function Find (str : string; var Index : integer) : boolean;
28 procedure Delete (Index : Integer);
29 property Items[Index : integer] : TSymbol read Get write Put; default;
30 procedure Save (s : TStream);
31 procedure Read (s : TStream);
32 end;
33
34
35 implementation
36
37 constructor TSymbol.Create;
38 begin
39 inherited Create;
40 hasValue := False;
41 Name := '';
42 value := 0.0;
43 end;
44
45
46 constructor TSymbol.Create (Name : string; value : double; hasValue : boolean);
47 begin
48 inherited Create;
49 self.hasValue := hasValue;
50 self.Name := Name;
51 self.value := Value;
52 end;
53
54 procedure TSymbol.Save (s : TStream);
55 begin
56 WriteString (s, Name);
57 WriteDouble (s, value);
58 s.Write (hasValue, sizeof (hasValue));
59 end;
60
61
62 constructor TSymbol.Read (s : TStream);
63 begin
64 Create;
65 Name := ReadStr (s);
66 Value := ReadDouble (s);
67 s.Read (hasValue, sizeof (hasValue));
68 end;
69
70 // -------------------------------------------------------------------------
71
72
73 constructor TSymbolList.Create;
74 begin
75 inherited Create;
76 end;
77
78
79 function TSymbolList.Get (Index : integer) : TSymbol;
80 begin
81 result := TSymbol(inherited Get(index));
82 end;
83
84
85 procedure TSymbolList.Put (Index : integer; Item : TSymbol);
86 begin
87 inherited Put (Index, Item);
88 end;
89
90
91 function TSymbolList.Add (Item : TSymbol) : integer;
92 begin
93 result := inherited Add (Item);
94 end;
95
96
97 function TSymbolList.Find (str : string; var Index : integer) : boolean;
98 var i : integer;
99 begin
100 result := False;
101 for i := 0 to Count - 1 do
102 if Items[i].Name = str then
103 begin
104 Index := i;
105 Result := True;
106 Exit;
107 end;
108 end;
109
110
111 procedure TSymbolList.Delete (Index : Integer);
112 begin
113 Items[Index].Free;
114 Items[Index] := nil;
115 inherited Delete (Index);
116 end;
117
118
119 destructor TSymbolList.Destroy;
120 var i : integer;
121 begin
122 for i := 0 to Count - 1 do
123 Items[i].Free;
124 inherited Destroy;
125 end;
126
127
128 procedure TSymbolList.Save (s : TStream);
129 var c, i : integer;
130 begin
131 c := Count;
132 s.Write (c, SizeOf (c));
133 for i := 0 to c - 1 do
134 Items[i].Save (s);
135 end;
136
137
138 procedure TSymbolList.Read (s : TStream);
139 var c, i : integer;
140 begin
141 s.Read (c, SizeOf (c));
142 for i := 0 to c - 1 do
143 Add (TSymbol.Read (s));
144 end;
145
146
147 end.