Patch: Improvement to TStringlist, allow custom sorted stringlists
Original Reporter info from Mantis: Braunbaer
-
Reporter name: Franz Müller
Original Reporter info from Mantis: Braunbaer
- Reporter name: Franz Müller
Description:
Currently, if a stringlist is custom sorted, the programmer has to call the sort routine each time new string items are added to the list, and sorting can only be done according to the string values, it cannot use values stored in the objects associated with the strings.
This patch introduces 2 new properties:
property OnCompareItems: TStringListSortCompare
If the programmer assign a custom compare function to this property (nil by default), the stringlist is sorted using this compare function, and is automatically kept sorted when items are added, if sortstyle=sslauto.
property ObjectSort : boolean
Must be set to true if the content of the object is relevant for sorting, because if that is the case, the indexof method has to search sequentially like in unsorted lists (binary search won't work).
If these properties are not changed, the stringlist behaves exactly like before.
Additional information:
Due to some optimizations of the code, sorting and searching is even a littler quicker than in the old version, in spite of the added flexibility.
The only exception to this is, that sort and find is somewhat slowed down when a derived class has overriden the docomparetext method, as in this case there is some overhead due to the different calling schemes.
Mantis conversion info:
- Mantis ID: 34873
- Platform: All
- Version: 3.3.1