7. 4. 2012

 

How to create case insensitive TDictionary<>


Very simple:

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

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

Indeed you can use TObjectDictionary<>. Tested in Delphi XE2.

Štítky: , ,