Solved

TList's method 'sort'

Posted on 1998-09-14
5
231 Views
Last Modified: 2010-04-06
Hello.

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

Thank you.

sakya
 
0
Comment
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
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:sakya
ID: 1339731
Edited text of question
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 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

by:JimBob091197
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

by:sakya
ID: 1339734
Thanks JimBob.
I appriciate your good answer.

sakya

0
 
LVL 5

Expert Comment

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

Cheers,
JB
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month5 days, 17 hours left to enroll

627 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