procedure StringGrid_SortCol(SG : TStringGrid; HideSGBefore : boolean; ACol : integer; TypeCol : integer; NrOpt : integer = 0);
{Сортировка по заданному столбцу}
Var
Vis,YesGreate : Boolean;
X1,X2 : real;
I1,I2 : integer;
dd,mm,yyyy : integer;
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 TypeCol=2 then begin //тип столбца : дата (dd.mm.yyyy)
if NrOpt<=0 then begin
if GetIDDateS_0(S1)>GetIDDateS_0(S2) then begin
YesGreate := TRUE;
end;
end
else begin
dd:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,1),0); //День
mm:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,2),0); //Мес
yyyy:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,3),0); //Год
I1:=GetIDDate(yyyy,mm,dd);
dd:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,1),0); //День
mm:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,2),0); //Мес
yyyy:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,3),0); //Год
I2:=GetIDDate(yyyy,mm,dd);
if I1>I2 then begin
YesGreate := TRUE;
end;
end;
end;
if TypeCol=3 then begin //тип столбца : неполная дата (dd.mm)
if NrOpt<=0 then begin
if GetIDMDS(S1)>GetIDMDS(S2) then begin
YesGreate := TRUE;
end;
end
else begin
dd:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,1),0); //День
mm:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S1,2),0); //Мес
I1:=GetIDMD(mm,dd);
dd:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,1),0); //День
mm:=saStrToInt(GetWordFromString99([' ','.','-','\','/'],S2,2),0); //Мес
I2:=GetIDMD(mm,dd);
if I1>I2 then begin
YesGreate := TRUE;
end;
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;