오라클의 order by 처럼 col1, col2 두개의 필드순으로 정렬하는방법을 델파이에서 퀵소트롤 하려고 하는데 잘 안되서서요
예를 들면 그리드에서 이름, 주민번호 두개의 칼럼이 있다고하면
이름순으로 정렬을 먼저하고 이름이 같은경우 주문번호으로해서
정렬을 하려고 하거든요어떻게 하면 될까요?
procedure TForm1.SortStringgrid(Grid: TStringGrid; byColumn: LongInt; ascending: Boolean);
procedure ExchangeGridRows(i, j: Integer);
var
k: Integer;
begin
with Grid do
for k := 0 to ColCount - 1 do
Cols[k].Exchange(i, j);
end;
procedure QuickSort(L, R: Integer);
var
I, J : Integer;
P : string;
begin
repeat
I := L;
J := R;
P := Grid.Cells[byColumn, (L + R) shr 1];
repeat
while CompareStr(Grid.Cells[byColumn, I], P) < 0 do Inc(I);
while CompareStr(Grid.Cells[byColumn, J], P) > 0 do Dec(J);
if I <= J then begin
if I <> J then
ExchangeGridRows(I, J);
Inc(I);
Dec(J);
end;
until I > J;
if L < J then QuickSort(L, J);
L := I;
until I >= R;
end;
procedure InvertGrid;
var
i, j: Integer;
begin
i := Grid.Fixedrows;
j := Grid.Rowcount - 1;
while i < j do begin
ExchangeGridRows(I, J);
Inc(i);
Dec(j);
end; { While }
end;
begin
Screen.Cursor := crHourglass;
Grid.Perform(WM_SETREDRAW, 0, 0);
try
QuickSort(Grid.FixedRows, Grid.Rowcount - 1);
if not ascending then
InvertGrid;
finally
Grid.Perform(WM_SETREDRAW, 1, 0);
Grid.Refresh;
Screen.Cursor := crDefault;
end;
end;
procedure TForm1.SortStringgrid(Grid: TStringGrid; byColumn: LongInt; ascending: Boolean);
procedure ExchangeGridRows(i, j: Integer);
var
k: Integer;
begin
with Grid do
for k := 0 to ColCount - 1 do
Cols[k].Exchange(i, j);
end;
procedure QuickSort(L, R: Integer);
var
I, J : Integer;
P : string;
begin
repeat
I := L;
J := R;
P := Grid.Cells[byColumn, (L + R) shr 1];
repeat
while CompareStr(Grid.Cells[byColumn, I], P) < 0 do Inc(I);
while CompareStr(Grid.Cells[byColumn, J], P) > 0 do Dec(J);
if I <= J then begin
if I <> J then
ExchangeGridRows(I, J);
Inc(I);
Dec(J);
end;
until I > J;
if L < J then QuickSort(L, J);
L := I;
until I >= R;
end;
procedure InvertGrid;
var
i, j: Integer;
begin
i := Grid.Fixedrows;
j := Grid.Rowcount - 1;
while i < j do begin
ExchangeGridRows(I, J);
Inc(i);
Dec(j);
end; { While }
end;
begin
Screen.Cursor := crHourglass;
Grid.Perform(WM_SETREDRAW, 0, 0);
try
QuickSort(Grid.FixedRows, Grid.Rowcount - 1);
if not ascending then
InvertGrid;
finally
Grid.Perform(WM_SETREDRAW, 1, 0);
Grid.Refresh;
Screen.Cursor := crDefault;
end;
end;