[fpc-pascal] Elegant way to switch sort mechanism in TSortedCollection?

Frederic Da Vitoria davitofrg at gmail.com
Thu Mar 13 21:49:48 CET 2014


2014-03-13 15:56 GMT+01:00 Jim Leonard <trixter at oldskool.org>:

> On 3/13/2014 9:49 AM, Jim Leonard wrote:
>
>> On 3/12/2014 6:58 PM, Philippe wrote:
>>
>>> you could
>>>
>>> - store the actual collection to a TMemoryStream,
>>>
>>> - destroy the collection,
>>>
>>> - Load then a new collect to be sort with different method ...
>>>
>>
>> Yes, that's what I'm doing now for every re-sort.
>>
>
> Actually, sorry, that's not *exactly* what I'm doing -- I'm creating a new
> TSortedCollection, using ForEach to iterate through the old collection to
> Insert into the new one, and then destroying the old one.  This copies only
> pointers (and runs through the Compare method) and is actually pretty fast
> -- it's just not elegant.
>
> If I stored the entire thing to a memory stream, it would copy all of the
> data and every re-sort would go pretty slowly.


You are sorting only for display purposes? If so, maybe VirtualTreeView
could do the trick.

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140313/4af9c092/attachment.html>


More information about the fpc-pascal mailing list