7

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 thorugh the Keys?

The workaroud I found is to create a TList<TKeyClass> but this is something i don't like.

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249

1 Answers1

14

Use an enumerator.

for Key in MyDictionary.Keys do
  ShowMessage(Key.AStringProperty);

Since TDictionary is a hash table, you can't access it with integer indexing like an array or TList. But an enumerator works just fine.

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477