This is another faster solution than before.
Instead of compare all entire data row, only compare the column selected data and uses mergesort to do the compare. To do it you need an auxiliar list with the old index and de data to compare to later with this list sorted, create the result list correcly.
procedure TStringGridMio.Sort(ColSorting: Boolean; index, IndxFrom, IndxTo: Integer);
procedure DuplicateRow( index_row : integer) ;
var
j : integer;
begin
rowcount := rowcount +1;
for j:= FixedCols to ColCount -1 do
begin
Cells[j,rowcount-1] := Cells[j,index_row];
end;
end;
var
list : TFPList;
i,j,k : integer;
string1 : string;
PDataSortable : ^DataSortable;
begin
if RowCount>FixedRows then begin
CheckIndex(ColSorting, Index);
CheckIndex(not ColSorting, IndxFrom);
CheckIndex(not ColSorting, IndxTo);
BeginUpdate;
list := TFPList.Create;
for i:= indxFrom to indxTo do
begin
new (PDataSortable);
PDataSortable^.index:=i;
PDataSortable^.value:=Cells[index,i];
list.Add(PDataSortable);
end;
MergeSort(list,@CompareDataSortable) ;
for i:= 0 to list.Count-1 do
begin
PDataSortable:=list.Items[i];
DuplicateRow(PDataSortable^.index);
Dispose(PDataSortable);
end;
for i:= indxFrom to indxTo do
begin
DeleteRow(indxFrom);
end;
list.free;
EndUpdate;
end;
end;