Hi!
I was bothered that the StringGrid only sorts in a lexical and not in a numeric way.
The StringGrid has the event
onCompareCells.
There you can interfere.
First you define:
Type
TSortType = (SortInt,SortUint, SortFloat,SortString);
var SortArray: array of TSortType;
Then you fill the Sortarray according to your columns.
Finaly you write the procedure for onCompareCells.
procedure TForm1.StringGrid1CompareCells(Sender: TObject; ACol, ARow, BCol,
BRow: Integer; var Result: integer);
var SortTag: TSortType;
begin
result := 0;
SortTag := SortArray[ACol];
with StringGrid1 do
begin
case SortTag of
SortInt :result := StrToInt64Def(Cells[ACol,ARow],0)-StrToInt64Def(Cells[BCol,BRow],0);
SortUint :result := StrToQWordDef(Cells[ACol,ARow],0)-StrToQwordDef(Cells[BCol,BRow],0);
SortFloat :result := round(StrToFloatDef(Cells[ACol,ARow],0)-StrToFloatDef(Cells[BCol,BRow],0));
SortString:result := UTF8CompareStr(Cells[ACol,ARow], Cells[BCol,BRow]);
end; // case
if SortOrder = soDescending then result := -result;
end;// with
end;
The result of
StringGrid1CompareCells is given into a Quicksort.
And this is quick as hell.
Below 10.000 rows you wont notice a delay.
Winni