tdictionary

TDictionary - invalid key

I have code like this: type TMyDictionary = TDictionary<int, int>; var myDict: TMyDictionary; k, v: integer; // code to fill the dictionary for k in myDict.Keys do begin v := myDict.Items[k]; // other stuff end; Randomly I see an exception thrown on 'v := myDict.Items[k];' which says k is invalid. Anyone e...

How Can I List a TDictionary in Alphabetical Order by Key in Delphi 2009?

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>; Enum: TPair<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...

Delphi's TDictionary, my Value objects are inserting as null.

Hi all, I'm using Delphi 9's TDictionary generic class. My TDictionary looks like this: g_FileHandlers : TDictionary<String, TList<String>>; And, so I initialize the TDictionary like so: g_FileHandlers := TDictionary<String, TList<String>>.Create; I have a TList, that I'm also initializing, so that I can use it to populate the TDi...

How to get the key from a TDictionary?

I have a TDictionary<TKeyClass, TValueClass>. I want to accomplish something like for i := 0 to MyDictionary.Count -1 do ShowMessage(MyDictionary.Keys[i].AStringProperty) I cannot Access the Keys anymore I can just use them if I exactly know them. Is the only alternative create a TDictionary<TValueClass, TKeyValue> ? So I can loop...