Search code examples
delphidelphi-2009tdictionary

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 else seen this?


Solution

  • Looking at CodeCentral I see a number of bugs raised against TDictionary and in particular the enumerator that supports the for ... in ... construct.