7. 4. 2012

 

How to create case insensitive TDictionary<>

Very simple:

uses System.Generics.Collections, System.Generics.Defaults;

var
  Dict: TDictionary‹string, TValue›;
begin
  Dict := TDictionary‹string, TValue›.Create(TIStringComparer.Ordinal); // ‹- this is the trick
  try
  .
  .
  .
  finally
    Dict.Free;
  end;
end;

Indeed you can use TObjectDictionary‹›. Tested in Delphi XE2.

Štítky: , ,