Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TList.Sort

Posted on 1999-01-18
2
Medium Priority
?
140 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
philipleighs earned 200 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

618 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