@@ -77,7 +77,8 @@ TCSSBuilder = class(TObject)
7777 // Class that maps CSS selector names to selector objects
7878 TCSSSelectorMap = TObjectDictionary<string,TCSSSelector>;
7979 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
8182 function GetSelector (const Selector: string): TCSSSelector;
8283 { Read access method for Selectors property. Returns selector object with
8384 given name.
@@ -105,10 +106,13 @@ TCSSBuilder = class(TObject)
105106 procedure Clear ;
106107 { Clears all selectors from style sheet and frees selector objects.
107108 }
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>
108114 function AsString : string;
109- { Generates CSS code representing the style sheet.
110- @return Required CSS code.
111- }
115+
112116 property Selectors[const Selector: string]: TCSSSelector
113117 read GetSelector;
114118 { Array of CSS selectors in style sheet, indexed by selector name}
@@ -189,26 +193,29 @@ function TCSSBuilder.AddSelector(const Selector: string): TCSSSelector;
189193begin
190194 Result := TCSSSelector.Create(Selector);
191195 fSelectors.Add(Selector, Result);
196+ fSelectorNames.Add(Selector);
192197end ;
193198
194199function TCSSBuilder.AsString : string;
195- { Generates CSS code representing the style sheet.
196- @return Required CSS code.
197- }
198200var
201+ SelectorName: string; // name of each selector
199202 Selector: TCSSSelector; // reference to each selector in map
200203begin
201204 Result := ' ' ;
202- for Selector in fSelectors.Values do
205+ for SelectorName in fSelectorNames do
206+ begin
207+ Selector := fSelectors[SelectorName];
203208 if not Selector.IsEmpty then
204209 Result := Result + Selector.AsString;
210+ end ;
205211end ;
206212
207213procedure TCSSBuilder.Clear ;
208214 { Clears all selectors from style sheet and frees selector objects.
209215 }
210216begin
211- fSelectors.Clear; // frees selector objects in .Values[]
217+ fSelectorNames.Clear;
218+ fSelectors.Clear; // frees owened selector objects in dictionary
212219end ;
213220
214221constructor TCSSBuilder.Create;
@@ -221,13 +228,15 @@ constructor TCSSBuilder.Create;
221228 fSelectors := TCSSSelectorMap.Create(
222229 [doOwnsValues], TTextEqualityComparer.Create
223230 );
231+ fSelectorNames := TList<string>.Create;
224232end ;
225233
226234destructor TCSSBuilder.Destroy;
227235 { Destructor. Tears down object.
228236 }
229237begin
230- fSelectors.Free; // frees selector objects in fSelectors.Values[]
238+ fSelectorNames.Free;
239+ fSelectors.Free; // frees owened selector objects in dictionary
231240 inherited ;
232241end ;
233242
0 commit comments