bubble sort for 2 colums

11 views
Skip to first unread message

lars.b...@gmail.com

unread,
Dec 16, 2014, 2:25:15 AM12/16/14
to
Hi

I am trying to sort a stringgrid by using a bubblesort procedure that I have found on the internet and with some small modification I have made it work.

I am a newbie when it comes to programming in delphi so I need some help to make this bubblesort program look in an other column aswell.

At the moment I have a stringgrid that I sort with column 1 (a-z) but I can have multiple entrys of eg. aaaa in column 1 so I need to look up column 4 to check the revision (numbers 1 and up).

My code looks like this:

procedure TForm1.SortGrid(Grid: TStringGrid; Col: integer);
var
Row, AllRowCount: integer;
prev: string;
begin
for AllRowCount:= 0 to Grid.RowCount- 1 do
for Row:= 2 to Grid.RowCount- 1 do
begin
if ((Grid.Cells[Col, Row]) <> '') then
if ((Grid.Cells[Col, Row-1])<> '') then
if (Grid.Cells[Col, Row]) < (Grid.Cells[Col, Row-1]) then
begin
prev:= Grid.Rows[Row- 1].CommaText;
Grid.Rows[Row- 1].CommaText:= Grid.Rows[Row].CommaText;
Grid.Rows[Row].CommaText:= prev;
end;
end;
end;

Thanks in advance for your help

-Baltzer
Reply all
Reply to author
Forward
0 new messages