Sorry, some Turbo Pascal-isms in my initial mail -- I see that FreePascal's TCollection class has an explicit .Sort method so this helps me re-sort on demand, but it doesn't help me switch the Compare method. So, my question still stands.

On 3/12/2014 1:51 PM, Jim Leonard wrote:
I'm working on a project that utilizes a TSortedCollection to help keep
items sorted during processing.  There is a need to re-sort the
collection by different criteria on-demand as the program runs.
(Different sort orders are an integral part of the processing.)

Unless I'm missing something, TSortedCollection lacks the ability to
change the Compare method after initialization and/or explicitly re-sort
the collection on-demand.  I was planning on handling each new (re)sort by:

1. Initializing a new TSortedCollection with the desired Compare method
2. Copying the contents from the old collection to the new one
3. Swap collection pointers; destroy the old collection.

This works without much penalty because the collection will never get
beyond a reasonable size, but the implementation makes me cringe.  Is
there a more elegant way to do this (without writing my own sort
routines for a plain TCollection)?


--
Jim Leonard (trix...@oldskool.org)
Check out some trippy MindCandy: http://www.mindcandydvd.com/
A child borne of the home computer wars: http://trixter.oldskool.org/
You're all insane and trying to steal my magic bag!
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to