Solved

TList.Sort

Posted on 1999-01-18
2
127 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now