Solved

TList.Sort

Posted on 1999-01-18
2
132 Views
Last Modified: 2010-04-06
Can someone explain how exactly the sort method of a TList is to be used?
Thanks.
0
Comment
Question by:franksymons
2 Comments
 
LVL 3

Accepted Solution

by:
philipleighs earned 50 total points
ID: 1362367
Hi,

Declare a function called MySortProc like this:

function MySortProc(Item1, Item2: Pointer): Integer;
  begin
    Result := 0;
    //Compare Item1 with Item2. Return -1, 0 or 1 for less, equal or greater
    //If the tlist object stores TYourClass objects, and you
    //want to sort by the Name property, then do this:
    if TYourClass(Item1).Name > TYourClass(Item2).Name then
      Result := 1
    else
    if TYourClass(Item1).Name < TYourClass(Item2).Name then
      Result := -1;
  end;


//Call this procedure to sort your list
procedure SortListOfYourClass(AList: TList);
  begin
    AList.Sort(MySortProc);
  end;


Cheers,
Phil.

PS: If you need more help, then describe what the list stores, and how you want to order the list items, and I'll give you some code to do it.
0
 

Author Comment

by:franksymons
ID: 1362368
Thanks, but do you have any idea why the sortprocedure can't be a method of a form or an object but has to be an ordinary procedure?
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question