Sorting TCollection (via it's private TList)
Posted on 2002-05-14
We have a large collection stored in a TCollection descendant for which I am implementing a sort.
A solution is to :
- copy the TCollection to a TObjectList
- call the TObjectList's sort (the algorithm is a really quick Quicksort)
- cycle through the TObjectList and reset the TCollectionItem.Index property for each item
This works but it is still a little sluggish for large collections, the big overhead being setting the index which does a Move.
However TCollection actually uses a TList itself but _unfortunately it's private_. We tried copying the VCL code for TCollection, opened access to the List and called the sort directly and it works lightening fast!
We don't know a way to have a TCollection descendant access the private TList without creating a new class in the VCL source unit. Does a hack exist?
Has anyone come up with a solution for sorting a TCollection that does not involve adding to the VCL source or setting the Items Index?
I would appreciate any suggestions,
Delphi 6 UP2