Solved

TList.Sort

Posted on 1999-01-18
2
135 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dynamically Created Query 3 78
Drag & Drop... Data from one grid to another 2 53
RESTRequest Parameter 4 79
QuickReport, Delphi, Shape 12 47
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

732 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