Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# TList's method 'sort'

Posted on 1998-09-14
Medium Priority
233 Views
Hello.

Please teach me how to use the TList's method 'sort'.
I want to sort an array of records.

Thank you.

sakya

0
Question by:sakya
[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
• 3
• 2

Author Comment

ID: 1339731
Edited text of question
0

LVL 5

Accepted Solution

JimBob091197 earned 150 total points
ID: 1339732
Hi

Set up a function CmpProc (or something else) as follows:

function CmpProc(Item1, Item2: Pointer): Integer;
begin
// Return 1 if Item1 > Item2.
if (TMyRec(Item1).RecStr > TMyRec(Item2).RecStr) then
Result := 1
else
Result := -1;
end;

(In my example I use TMyRec which looks like this:
type
TMyRec = record
RecStr: string;
end;
)

Then call "MyList.Sort(CmpProc);"

Cheers,
JB

0

LVL 5

Expert Comment

ID: 1339733
Change CmpProc to the following:

function CmpProc(Item1, Item2: Pointer): Integer;
if (TMyRec(Item1^).RecStr = TMyRec(Item2^).RecStr) then
Result := 0
else if (TMyRec(Item1^).RecStr > TMyRec(Item2^).RecStr) then
Result := 1
else
Result := -1;
end;

JB
0

Author Comment

ID: 1339734
Thanks JimBob.

sakya

0

LVL 5

Expert Comment

ID: 1339735
You're welcome.  If there's any more help I can give, just ask.

Cheers,
JB
0

## Featured Post

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
###### Suggested Courses
Course of the Month6 days, 5 hours left to enroll