1 | unit SpecializedList;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, GenericList;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TListByte = class(TGList<Byte>)
|
---|
12 | procedure WriteToStream(Stream: TStream);
|
---|
13 | procedure WriteToStreamPart(Stream: TStream; ItemIndex, ItemCount: Integer);
|
---|
14 | procedure ReplaceStream(Stream: TStream);
|
---|
15 | procedure ReplaceStreamPart(Stream: TStream; ItemIndex, ItemCount: Integer);
|
---|
16 | procedure AddStream(Stream: TStream);
|
---|
17 | procedure AddStreamPart(Stream: TStream; ItemCount: Integer);
|
---|
18 | end;
|
---|
19 |
|
---|
20 | TListChar = class(TGList<Char>)
|
---|
21 | procedure UpperCase;
|
---|
22 | procedure LowerCase;
|
---|
23 | procedure Trim;
|
---|
24 | procedure TrimLeft;
|
---|
25 | procedure TrimRight;
|
---|
26 | end;
|
---|
27 |
|
---|
28 | TListMethod = class(TGList<TMethod>)
|
---|
29 | procedure CallAll;
|
---|
30 | end;
|
---|
31 |
|
---|
32 | TListNotifyEvent = class(TGList<TNotifyEvent>)
|
---|
33 | procedure CallAll(Sender: TObject);
|
---|
34 | end;
|
---|
35 |
|
---|
36 | TSimpleEvent = procedure of object;
|
---|
37 | TListSimpleEvent = class(TGList<TSimpleEvent>)
|
---|
38 | procedure CallAll;
|
---|
39 | end;
|
---|
40 |
|
---|
41 | function StrToStr(Value: string): string;
|
---|
42 |
|
---|
43 |
|
---|
44 | implementation
|
---|
45 |
|
---|
46 | function StrToStr(Value: string): string;
|
---|
47 | begin
|
---|
48 | Result := Value;
|
---|
49 | end;
|
---|
50 |
|
---|
51 | { TListSimpleEvent }
|
---|
52 |
|
---|
53 | procedure TListSimpleEvent.CallAll;
|
---|
54 | var
|
---|
55 | I: Integer;
|
---|
56 | begin
|
---|
57 | I := 0;
|
---|
58 | while (I < Count) do begin
|
---|
59 | TSimpleEvent(Items[I])();
|
---|
60 | I := I + 1;
|
---|
61 | end;
|
---|
62 | end;
|
---|
63 |
|
---|
64 |
|
---|
65 | { TListChar }
|
---|
66 |
|
---|
67 | procedure TListChar.UpperCase;
|
---|
68 | var
|
---|
69 | I: Integer;
|
---|
70 | begin
|
---|
71 | for I := 0 to Count - 1 do
|
---|
72 | if (FItems[I] in ['a'..'z']) then
|
---|
73 | FItems[I] := Char(Byte(FItems[I]) - 32);
|
---|
74 | end;
|
---|
75 |
|
---|
76 | procedure TListChar.LowerCase;
|
---|
77 | var
|
---|
78 | I: Integer;
|
---|
79 | begin
|
---|
80 | for I := 0 to Count - 1 do
|
---|
81 | if (FItems[I] in ['A'..'Z']) then
|
---|
82 | FItems[I] := Char(Byte(FItems[I]) + 32);
|
---|
83 | end;
|
---|
84 |
|
---|
85 | procedure TListChar.Trim;
|
---|
86 | begin
|
---|
87 | TrimLeft;
|
---|
88 | TrimRight;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | procedure TListChar.TrimLeft;
|
---|
92 | var
|
---|
93 | I: Integer;
|
---|
94 | begin
|
---|
95 | I := 0;
|
---|
96 | while (I < Count) and (FItems[I] = ' ') do
|
---|
97 | I := I + 1;
|
---|
98 | if I < Count then
|
---|
99 | DeleteItems(0, I);
|
---|
100 | end;
|
---|
101 |
|
---|
102 | procedure TListChar.TrimRight;
|
---|
103 | var
|
---|
104 | I: Integer;
|
---|
105 | begin
|
---|
106 | I := Count - 1;
|
---|
107 | while (I >= 0) and (FItems[I] = ' ') do
|
---|
108 | I := I - 1;
|
---|
109 | if I >= 0 then
|
---|
110 | DeleteItems(I + 1, Count - I - 1);
|
---|
111 | end;
|
---|
112 |
|
---|
113 | procedure TListMethod.CallAll;
|
---|
114 | var
|
---|
115 | I: Integer;
|
---|
116 | begin
|
---|
117 | I := 0;
|
---|
118 | while (I < Count) do begin
|
---|
119 | Items[I];
|
---|
120 | I := I + 1;
|
---|
121 | end;
|
---|
122 | end;
|
---|
123 |
|
---|
124 | procedure TListNotifyEvent.CallAll(Sender: TObject);
|
---|
125 | var
|
---|
126 | I: Integer;
|
---|
127 | begin
|
---|
128 | I := Count - 1;
|
---|
129 | while (I >= 0) do begin
|
---|
130 | TNotifyEvent(Items[I])(Sender);
|
---|
131 | I := I - 1;
|
---|
132 | end;
|
---|
133 | end;
|
---|
134 |
|
---|
135 | { TListByte }
|
---|
136 |
|
---|
137 | procedure TListByte.WriteToStream(Stream: TStream);
|
---|
138 | var
|
---|
139 | I: Integer;
|
---|
140 | begin
|
---|
141 | Stream.Position := 0;
|
---|
142 | I := 0;
|
---|
143 | while I < Count do begin
|
---|
144 | Stream.WriteByte(Items[I]);
|
---|
145 | I := I + 1;
|
---|
146 | end;
|
---|
147 | end;
|
---|
148 |
|
---|
149 | procedure TListByte.WriteToStreamPart(Stream: TStream; ItemIndex, ItemCount: Integer);
|
---|
150 | var
|
---|
151 | I: Integer;
|
---|
152 | begin
|
---|
153 | I := ItemIndex;
|
---|
154 | while I < ItemCount do begin
|
---|
155 | Stream.WriteByte(Items[I]);
|
---|
156 | I := I + 1;
|
---|
157 | end;
|
---|
158 | end;
|
---|
159 |
|
---|
160 | procedure TListByte.ReplaceStream(Stream: TStream);
|
---|
161 | var
|
---|
162 | I: Integer;
|
---|
163 | begin
|
---|
164 | Stream.Position := 0;
|
---|
165 | I := 0;
|
---|
166 | while I < Count do begin
|
---|
167 | Items[I] := Stream.ReadByte;
|
---|
168 | I := I + 1;
|
---|
169 | end;
|
---|
170 | end;
|
---|
171 |
|
---|
172 | procedure TListByte.ReplaceStreamPart(Stream: TStream; ItemIndex,
|
---|
173 | ItemCount: Integer);
|
---|
174 | var
|
---|
175 | I: Integer;
|
---|
176 | begin
|
---|
177 | I := ItemIndex;
|
---|
178 | while I < ItemCount do begin
|
---|
179 | Items[I] := Stream.ReadByte;
|
---|
180 | I := I + 1;
|
---|
181 | end;
|
---|
182 | end;
|
---|
183 |
|
---|
184 | procedure TListByte.AddStream(Stream: TStream);
|
---|
185 | var
|
---|
186 | I: Integer;
|
---|
187 | begin
|
---|
188 | Stream.Position := 0;
|
---|
189 | I := Count;
|
---|
190 | Count := Count + Stream.Size;
|
---|
191 | while I < Count do begin
|
---|
192 | Items[I] := Stream.ReadByte;
|
---|
193 | I := I + 1;
|
---|
194 | end;
|
---|
195 | end;
|
---|
196 |
|
---|
197 | procedure TListByte.AddStreamPart(Stream: TStream; ItemCount: Integer);
|
---|
198 | var
|
---|
199 | I: Integer;
|
---|
200 | begin
|
---|
201 | I := Count;
|
---|
202 | Count := Count + ItemCount;
|
---|
203 | while I < Count do begin
|
---|
204 | Items[I] := Stream.ReadByte;
|
---|
205 | I := I + 1;
|
---|
206 | end;
|
---|
207 | end;
|
---|
208 |
|
---|
209 | end.
|
---|