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
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!
> {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.
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)