[Lazarus] Example of TObjectList sorting

Richard Mace richard.mace at gmail.com
Sat May 21 12:49:54 CEST 2016


Hi Denis,

Thanks for your reply.

On 9 May 2016 at 13:24, Denis Kozlov <dezlov at gmail.com> wrote:

> On 9 May 2016 at 12:48, Richard Mace <richard.mace at gmail.com> wrote:
>
>> I have a TObjectList that contains many objects that have a property
>> called "Position" which is an integer.
>>
>> Could somebody show me an example of the code that I will need to create
>> that will sort all of my Objects within the TObjectList so that they are in
>> position order e.g. 1,2,3,4,5 and so on?
>>
>
> Call TList.Sort method and supply a comparison function.
>
>
> For example:
>
> List.Sort(@CompareByPositionPtr);
>

​Would I call the List.sort externally, or would the List call sort when an
Add has happened, as I don't seem to have a ".sort" method on my
TObjectList?

Thanks​

​Richard​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160521/1187da0a/attachment-0003.html>


More information about the Lazarus mailing list