Iterating through a disk dictionary

This example shows how to use TDiskDictionaryIterator to step through the dictionary one key-value pair at a time. Remember that the values are returned in no specific order.

First a new iterator is created. Then for myCount iterations, the iterator accesses the next key-value pair. If the count is 0 (the first element) then retrieve the first pair. For all other counts retrieve the next pair.

NOTE Key-value pairs are sometimes referred to as associations..

          // example using TDiskDictionaryIterator
          TDiskDictionaryIterator* myIterator = new TDiskDictionaryIterator(dict);
          
          for (i=0; i=myCount; i++ ) {
              if (i==0)
                  myAssoc = myIterator->First();
              else
                  myAssoc = myIterator->Next();
              if (myAssoc)
                  delete myAssoc;
              else
                  {
                  qprintf("No Assoc exists for i = %d  ",i);
                  if (i == myCount)
                      qprintf("This is expected.\n");
                  else
                      qprintf("This is NOT expected!\n");
                  break;
                  }
          }
          delete myIterator;

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker