
07.07.2010, 23:07
|
Активный
|
|
Регистрация: 15.04.2009
Сообщения: 369
Репутация: 93
|
|
Как вариант :
Код:
procedure StringGrid_SortCol(SG : TStringGrid; HideSGBefore : boolean; ACol : integer; TypeCol : integer);
{Сортировка по заданному столбцу}
{HideSGBefore - скрыть на время процесса}
{ACol - номер столбца}
{TypeCol - тип столбца}
Var
Vis,YesGreate : Boolean;
X1,X2 : real;
S1,S2,S0 : string;
ListS : TStrings;
Res,N,k,j,i : LongInt;
begin
if SG<>NIL then begin
if SG.RowCount>1 then begin
if (ACol>=0) and (ACol<SG.ColCount) then begin
Vis:=SG.Visible;
if HideSGBefore then SG.Visible:=FALSE;
ListS:=TStringList.Create;
TRY
N:=SG.RowCount-1;
for i:=1 to N do
begin
k:=N-i;
for j:=1 to k do
begin
YesGreate := FALSE;
S1:=SG.Cells[ACol,j];
S2:=SG.Cells[ACol,j+1];
S1:=Trim(S1);
S2:=Trim(S2);
{[1,6,11,14]}
if TypeCol=(-1) then begin //тип столбца : строка UpCase
S1:=AnsiUpperCase(S1);
S2:=AnsiUpperCase(S2);
if S1>S2 then begin
YesGreate := TRUE;
end;
end;
if TypeCol=0 then begin //тип столбца : строка
if S1>S2 then begin
YesGreate := TRUE;
end;
end;
if TypeCol=1 then begin //тип столбца : число
Val(S1,X1,Res);
Val(S2,X2,Res);
if X1>X2 then begin
YesGreate := TRUE;
end;
end;
if YesGreate then begin
ListS.Assign(SG.Rows[j]);
SG.Rows[j].Assign(SG.Rows[j+1]);
SG.Rows[j+1].Assign(ListS);
end;
end;
end;
FINALLY
if ListS<>NIL then begin
ListS.Free;
end;
ListS:=NIL;
SG.Visible:=Vis;
END;
end;
end;
end;
end;
|