How Can I List a TDictionary in Alphabetical Order by Key in Delphi 2009?
- by lkessler
How can I use a TEnumerator to go through my TDictionary in sorted order by key?
I've got something like this:
var
Dic: TDictionary<string, string>;
begin
Dic := TDictionary<string, string>.create;
Dic.Add('Tired', 'I have been working on this too long');
Dic.Add('Early', 'It is too early in the morning to be working on this');
Dic.Add('HelpMe', 'I need some help');
Dic.Add('Dumb', 'Yes I know this example is dumb');
{ The following is what I don't know how to do }
for each string1 (ordered by string1) in Dic do
some processing with the current Dic element
Dic.Free;
end;
So I would like to process my dictionary in the order: Dumb, Early, HelpMe, Tired.
Unfortunately the Delphi help is very minimal in describing how TEnumerator works and gives no examples that I can find. There is also very little written on the web about using Enumerators with Generics in Delphi.