Mega Search
23.2 Million


Sign Up

Make a donation  
Objects list  
News Group: embarcadero.public.delphi.oodesign

I would need to create a container of objects (different objects) able to be referred them by a key (integer) as does for example the TDictionary object, but that it is also able to be ordered for position index as a simple TObjectList.
Is there an elegant way to solve this problem without having to manage a double list?

thanks
Lorenzo

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 4-Dec-2014, at 12:12 AM EST
From: Lorenzo Biondi
 
Re: Objects list  
News Group: embarcadero.public.delphi.oodesign
At this point I think I will have to proceed in the creation of an object provided with a special double list. I had created the post more than anything else to be sure that there was already something ready, you know I have an innate tendency that leads me frequently to reinvent the wheel!
Beautiful also the idea of the table with indexed!
Thanks!

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 5-Dec-2014, at 1:27 AM EST
From: Lorenzo Biondi
 
Re: Objects list  
News Group: embarcadero.public.delphi.oodesign
> {quote:title=Lorenzo Biondi wrote:}{quote}
> I would need to create a container of objects (different objects) able to be referred them by a key (integer) as does for example the TDictionary object, but that it is also able to be ordered for position index as a simple TObjectList.
> Is there an elegant way to solve this problem without having to manage a double list?

Could you create a container class with indexing ability? Think database table with indexes into that table. That would require additional *lists* internal to the container.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Dec-2014, at 9:52 AM EST
From: > Rich
 
Re: Objects list  
News Group: embarcadero.public.delphi.oodesign
Lorenzo Biondi wrote:

> I would need to create a container of objects (different objects)
> able to be referred them by a key (integer) as does for example the
> TDictionary object, but that it is also able to be ordered for
> position index as a simple TObjectList.  Is there an elegant way to
> solve this problem without having to manage a double list?

Not really, the two access options you want to have are mutually
exclusive, unless the order by position happens to be the same as the
sort order of the keys. I that case you could sort the TObjectlist on
the key and use binary search to find an entry by key.

By the way: if you actually just need a way to iterate over all entries
and do not care about the order: TDictionary does support enumerators,
for its key and value collections, and for the pairs of both.

-- 
Peter Below (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Dec-2014, at 9:18 AM EST
From: Peter Below