use the following unit: unit StringMyObjectMap;
{$mode objfpc}{$H+} interface uses ghashmap; type TStringHash = class class function hash(s: String; n: Integer): Integer; end; TMyObject = class ... end; // define yourself TStringMyObjectMap = class(specialize THashMap<String,TMyObject,TStringHash>) destructor Destroy; override; end; implementation class function TStringHash.hash(s: String; n: Integer): Integer; var c: Char; begin Result := 0; for c in s do Inc(Result,Ord(LowerCase(c))); // remove LowerCase if you want the key search to be case sensitive Result := Result mod n; end; destructor TStringMyObjectMap.Destroy; var It: TIterator; begin if Size > 0 then begin It := Iterator; repeat It.Value.Free; until not It.Next; It.Free; end; inherited Destroy; end; end. WARNING: untested code, though I'm quite sure it works fine -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Generics-how-to-rewrite-TOjectDictionary-tp5714029p5714045.html Sent from the Free Pascal - General mailing list archive at Nabble.com. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal