[fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-10 Thread leledumbo
Oops, my bad. There's actually a bug in the search. It will still be case sensitive despite the hash function uses lowercase-d version of the key. It only affects the items distribution, but the key is still searched in case sensitive way through the selected bucket. -- View this message in cont

[fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-09 Thread Marius
leledumbo wrote: >use the following unit: > >unit StringMyObjectMap; Thanks, That is a pretty advanced piece of generics, I found the fpc sources together with the hasmapexample. I'm afraid i need to play to get comfortable with generics g> but it will get me on my way.. (Sorry I had some t

[fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-09 Thread Marius
Sven Barth wrote: >But I now remember that we added an OwnsObjects property to >TStringList some time ago... Magic, I honestly have to admitt I was not aware of that, thanks! ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.free

[fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-09 Thread Marius
dmitry boyarintsev wrote: >function GetMyObject(dic: TStrings; const nm: string): TMyObject; It is one of the few solutions to share the code between delphi and fpc (and yes, i would probably encase it in another class to hide the typecasting). Still need to figure out how hashing compare to stri

[fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-09 Thread Marius
Marco van de Voort wrote: > >There is fgl.tfglmap and variants. Thank you Marco, I was aware of this class but have to study it more nefore using it.. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/

[fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-08 Thread leledumbo
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) destru

Re: [fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-08 Thread dmitry boyarintsev
please disregard my last note about "avoiding the sanity check" On Mon, Apr 8, 2013 at 1:52 PM, dmitry boyarintsev < skalogryz.li...@gmail.com> wrote: > You can always use functions, to fight typecasting. > > function GetMyObject(dic: TStrings; const nm: string): TMyObject; > var > i : intege

Re: [fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-08 Thread dmitry boyarintsev
You can always use functions, to fight typecasting. function GetMyObject(dic: TStrings; const nm: string): TMyObject; var i : integer; begin if not Assigned(dic) then begin Result:=nil; Exit; end; i:=dic.indexof(nm); // replace with IndexOfName if necessary if (i<0) or (i>=dic.Count) or no

Re: [fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-08 Thread Sven Barth
Am 08.04.2013 10:18, schrieb Marco van de Voort: In our previous episode, Marius2 said: Yes, I have used it lots of times and its really the last choice if theres something available like the objectdictionary. In this case the dict is also the owner of the objects, it saves me the continious ugl

Re: [fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-08 Thread Marco van de Voort
In our previous episode, Marius2 said: > Yes, I have used it lots of times and its really the last choice if theres > something available like the objectdictionary. In this case the dict is also > the owner of the objects, it saves me the continious ugly typecasting, takes > care of the extra admin

[fpc-pascal] Re: Generics - how to rewrite TOjectDictionary

2013-04-08 Thread Marius2
Thanks Dimitri, Yes, I have used it lots of times and its really the last choice if theres something available like the objectdictionary. In this case the dict is also the owner of the objects, it saves me the continious ugly typecasting, takes care of the extra administration with freeing objects