Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TList

Status
Not open for further replies.

ttRacer

Programmer
Feb 18, 2002
1
GB
I am having trouble sorting a Tlist object, I need to sort by three different columns, i.e. sort on column 1 then column 2 then column 3.
Is the only way to do this by declaring all the possible scenarios in the Compare function?


e.g.

A B C
C D A
A B A
B c D
B c A
B D A
A B B
C A D



SORTED

A B A
A B B
A B C
B C A
B C D
B D A
C A D
C D A

cheers
tt
 
The simplest way to sort is by building a string out of the columns to be sorted, i.e. write a function

function GetSortString(Row: integer): string;
begin
Result := Table[0, Row] + Table[1, Row] + Table[2, Row];
end;

Now it's easy to compare two rows by this sorting criterium.

Of course you have to pad each column to a fixed length to compare them.

good luck
Roderich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top