Board index » delphi » Newbie: How to use TList.Sort?

Newbie: How to use TList.Sort?

In delphi 2 at least the sort method only applies to TStringLists (at
least I think it does):-

StringListName.sort; {will sort the string list into alphabetical order}

Hope this helps

Tim Newton
http://www.btinternet.com/~timn

Quote
Ivar Katmo wrote:

> Hi!

> Can anyone give a short example that show how TList.Sort is used?

> Ivar Katmo
> Trondheim, Norway

 

Re:Newbie: How to use TList.Sort?


Hi!

Can anyone give a short example that show how TList.Sort is used?

Ivar Katmo
Trondheim, Norway

Re:Newbie: How to use TList.Sort?


In article <64cs74$fj...@due.unit.no>, "Ivar Katmo" <iva...@stud.ntnu.no>
writes:

Quote
>Can anyone give a short example that show how TList.Sort is used?

TList.Sort(function_name) sorts the pointers on whatever you specify in
the function.
It can be the pointer values themselves (weird, I'm not sure why you would
want that), the order of the values pointed to, or whatever. The function
specified must take two generic pointers (hence they must usually be cast
when de-referenced) and return 0 if they are equal, less than 0 if the
first is less than the second, or greater than 0.
'equal', 'less than' etc is up to you to define in the code encapsulated
in the function.

See program below for an example of two sorts of sorts <g>.

Hope this helps

Alan Lloyd
alangll...@aol.com

_=_
_=_ Part 001 of 001 of file Sort.zip
_=_

begin 666 Sort.zip
<encoded_portion_removed>
end

Re:Newbie: How to use TList.Sort?


In article <346A367A.2F531...@bigfoot.com>, Tim Newton <t...@bigfoot.com>
writes:

Quote
>In delphi 2 at least the sort method only applies to TStringLists (at
>least I think it does):-

Not so
 D2 TList has a Sort method called with TList.Sort(MySortFunction).
MySortFunction takes two pointers and returns your evaluation of their
order,(<0, 0, >0). The TList is sorted on this order. See my previous message.

Alan Lloyd
alangll...@aol.com

Other Threads