TrDBGridSorter not cleared when the dataset is closed and reused (regression?)

5 views
Skip to first unread message

Péter Ádám

unread,
Jan 18, 2026, 1:50:54 PM (5 days ago) Jan 18
to Rosi Delphi Components
Hello

I am using the TrDBGridSorter and a TrDBToolBar for filtering in Zeos flavor for production, and FireDac for test in a supported configuration.
The code switches the SQL query behind a TrDBGrid, and without sorting, it works as expected.

18.2 (Zeos)
But with sorting, it throws an exception if the new query does not have a field named as the sorting field.
Workaround:
  with rDGTableEditor do
  begin
    SortFieldName := '';
    ChangeSort('', false);
  end;
Filtering correctly clears itself on closing the dataset, but sorting does not.

18.3 (FireDac)
Both sorting and filtering throws an exception
Workaround not working, I always get an exception, then clears the sort
Without workaround it never ceases to throw exceptions, plus on 2+ runs adds a single _ (underscore) to the sorted field so it is even worse.

The last thing I have tried was:

procedure TForm1.SetDataSet(ASql: string);
begin
  (* Workaround *)
  with rDBGrid1 do
  begin
    SortFieldName := '';
    ChangeSort('', false);
    DataSource := nil;
  end;
  (* /Workaround *)
  with FDQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from ' + ASql);
    Open;
  end;
  (* Workaround *)
  with rDBGrid1 do
  begin
    DataSource := DataSource1;
  end;
end;

Calling:

procedure TForm1.BQuery1Click(Sender: TObject);
begin
  SetDataSet('l_afabevallas');
end;

procedure TForm1.BQuery2Click(Sender: TObject);
begin
 SetDataSet('szamlatipus');
end;

Exception:

:00007FF82905A80A RaiseException
@InternalRaiseAtExcept(??,??,??)
@RaiseAtExcept(??,??)
FDException($000001f05f153b70,$000001f05f1a0540,false)
FDException($000001f05f153b70,{[0]='DatS'},2,{[0]={{_Reserved1=2131899201056,VType=17}}})
TFDDatSNamedList.ErrorNameNotFound(??,??)
TFDDatSNamedList.ItemByName(??,??)
TFDDatSBindedList.ItemByName(??,??)
TFDDatSColumnList.ColumnByName(??,??)
TFDDatSColumnSublist.Fill($000001f062102aa0,$000001f05f171210,'NEV',$000001f0621035e0,$000001f062103550)
TFDDatSMechSort.DoActiveChanged($000001f05f171210)
TFDDatSMechBase.CheckActiveChanged($000001f05f171210)
TFDDatSView.CheckActiveChanged($000001f05f17c010)
TFDDatSView.SetActive(??,??)
TFDDataSet.BuildViewForIndex($000001f05f0706c0,$000001f05f13ffd0)
TFDIndex.CreateView($000001f05f13ffd0)
DeleteCreateView
TFDIndex.IndexChanged($000001f05f13ffd0)
TFDIndexes.Build($000001f062113dc0)
TFDDataSet.OpenIndexes($000001f05f0706c0)
TFDDataSet.InternalOpen($000001f05f0706c0)
TDataSet.DoInternalOpen($000001f05f0706c0)
TDataSet.OpenCursor(??,??)
TFDDataSet.OpenCursor($000001f05f0706c0,false)
TFDRdbmsDataSet.OpenCursor($000001f05f0706c0,false)
TDataSet.SetActive($000001f05f0706c0,true)
TFDDataSet.SetActive(??,??)
TDataSet.Open(??)
TForm1.SetDataSet($000001f05f0d3780,'szamlatipus')

How to properly clear filtering and sorting when reusing the dataset with different SQLs?

Best regards,
Peter

Tomas Rosinsky

unread,
Jan 19, 2026, 12:01:26 PM (4 days ago) Jan 19
to Rosi Delphi Components
Hello Peter,

usually one rDBGrid is used for one dataset and therefore it keeps current Filter and Sorting setting also after dataset refresh (or close and open).

If you change dataset and fields for the existing rDBGrid then you should also reset sorting and filtering by following code before you change dataset:


myGrid.ChangeSortEx('', '');
myGrid.ResetFilter;
 

I will check and implement possible solution for automatic reset after dataset close.

I hope it helps
Tomas

Dne neděle 18. ledna 2026 v 19:50:54 UTC+1 uživatel lape...@gmail.com napsal:
Reply all
Reply to author
Forward
0 new messages