R – TDictionary – invalid key

delphidelphi-2009tdictionary

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?

Best Answer

Are you modifying myDict inside the section labeled // other stuff?

Related Topic