くだすれDelphi(超初心者用)その26
■ このスレッドは過去ログ倉庫に格納されています
0412410
2005/08/08(月) 23:32:30時間が空いたので書いてみた。ソートは文字列リストに任せる手抜き処理。
SortGrid(対象のStringGird, ソートカラム�ajで呼び出す。件数が多くなると遅くなりそう。。。
改行が多いって怒られたのでちょっと詰めてカキコするから見づらいのは勘弁。
procedure SortGrid(oGrid: TStringGrid; iSortCol: Integer);
type PCellData = ^TCellData; TCellData = record sData:array of AnsiString; end;
var oSortList:TStringList; iCol, iRow, iIndex:Integer; pData:PCellData;
begin
oSortList := TStringList.Create;
try
for iRow := oGrid.FixedRows to oGrid.RowCount - 1 do begin
New(pData); SetLength(pData^.sData, oGrid.ColCount);
for iCol := oGrid.FixedCols to oGrid.ColCount - 1 do
pData^.sData[iCol] := oGrid.Cells[iCol, iRow];
oSortList.AddObject(oGrid.Cells[iSortCol, iRow], TObject(pData));
end;
oSortList.Sort;
for iIndex := 0 to oSortList.Count - 1 do begin
pData := PCellData(oSortList.Objects[iIndex]); iRow := oGrid.FixedRows + iIndex;
for iCol := oGrid.FixedCols to oGrid.ColCount - 1 do
oGrid.Cells[iCol, iRow] := pData^.sData[iCol];
Dispose(pData);
end;
finally
oSortList.Free;
end;
end;
■ このスレッドは過去ログ倉庫に格納されています