@@ -77,7 +77,8 @@ TCSSBuilder = class(TObject)
77
77
// Class that maps CSS selector names to selector objects
78
78
TCSSSelectorMap = TObjectDictionary<string,TCSSSelector>;
79
79
var
80
- fSelectors: TCSSSelectorMap; // Maps selector names to selector objects
80
+ fSelectors: TCSSSelectorMap; // Maps selector names to selector objects
81
+ fSelectorNames: TList<string>; // Lists selector names in order created
81
82
function GetSelector (const Selector: string): TCSSSelector;
82
83
{ Read access method for Selectors property. Returns selector object with
83
84
given name.
@@ -105,10 +106,13 @@ TCSSBuilder = class(TObject)
105
106
procedure Clear ;
106
107
{ Clears all selectors from style sheet and frees selector objects.
107
108
}
109
+
110
+ // / <summary>Generates CSS code representing the style sheet.</summary>
111
+ // / <returns><c>string</c>. The required CSS.</returns>
112
+ // / <remarks>The selectors are returned in the order they were created.
113
+ // / </remarks>
108
114
function AsString : string;
109
- { Generates CSS code representing the style sheet.
110
- @return Required CSS code.
111
- }
115
+
112
116
property Selectors[const Selector: string]: TCSSSelector
113
117
read GetSelector;
114
118
{ Array of CSS selectors in style sheet, indexed by selector name}
@@ -189,26 +193,29 @@ function TCSSBuilder.AddSelector(const Selector: string): TCSSSelector;
189
193
begin
190
194
Result := TCSSSelector.Create(Selector);
191
195
fSelectors.Add(Selector, Result);
196
+ fSelectorNames.Add(Selector);
192
197
end ;
193
198
194
199
function TCSSBuilder.AsString : string;
195
- { Generates CSS code representing the style sheet.
196
- @return Required CSS code.
197
- }
198
200
var
201
+ SelectorName: string; // name of each selector
199
202
Selector: TCSSSelector; // reference to each selector in map
200
203
begin
201
204
Result := ' ' ;
202
- for Selector in fSelectors.Values do
205
+ for SelectorName in fSelectorNames do
206
+ begin
207
+ Selector := fSelectors[SelectorName];
203
208
if not Selector.IsEmpty then
204
209
Result := Result + Selector.AsString;
210
+ end ;
205
211
end ;
206
212
207
213
procedure TCSSBuilder.Clear ;
208
214
{ Clears all selectors from style sheet and frees selector objects.
209
215
}
210
216
begin
211
- fSelectors.Clear; // frees selector objects in .Values[]
217
+ fSelectorNames.Clear;
218
+ fSelectors.Clear; // frees owened selector objects in dictionary
212
219
end ;
213
220
214
221
constructor TCSSBuilder.Create;
@@ -221,13 +228,15 @@ constructor TCSSBuilder.Create;
221
228
fSelectors := TCSSSelectorMap.Create(
222
229
[doOwnsValues], TTextEqualityComparer.Create
223
230
);
231
+ fSelectorNames := TList<string>.Create;
224
232
end ;
225
233
226
234
destructor TCSSBuilder.Destroy;
227
235
{ Destructor. Tears down object.
228
236
}
229
237
begin
230
- fSelectors.Free; // frees selector objects in fSelectors.Values[]
238
+ fSelectorNames.Free;
239
+ fSelectors.Free; // frees owened selector objects in dictionary
231
240
inherited ;
232
241
end ;
233
242
0 commit comments