O'Reilly logo

Delphi for .NET Developer’s Guide by Xavier Pacheco

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Strongly-Typed Dictionary

As with the Collection, it is likely that you might need a strongly-typed Dictionary. In the HashTable example presented in this chapter, the data stored could have been any type descending from System.Object. The following section illustrates how to create a Dictionary that enforces the TStateInfo type.

Descending from DictionaryBase

The System.Collections namespace defines the DictionaryBase class. From this class, you should derive your strongly-typed dictionary classes. Listing 10.7 shows such a class.

Listing 10.7. Strongly-Typed Dictionary
1: unit d4dnDevGuide.StateDictionary; 2: interface 3: 4: uses 5: System.Collections; 6: 7: type 8: 9: // Define a class to store in the dictionary 10: TStateInfo = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required