delphifiredactlistviewfdmemtable

TFDMemTable filter not responding to my TEdit OnChangeTracking


I have TFDMemTable data from API. The TFDMemTable is livebinded with TListView. The tricky part here is that, I want to show in the TListView the filtered data only using OnChangeTracking event of TEdit control.

Here's the code that I am working with to effect my intended result but, unfortunately, it is not returning anything.

procedure TformMain.edtSearchBoxChangeTracking(Sender: TObject);
var
  metastr : string;
begin
  metastr := edtSearchBox.text;   //edtSearchBox is my TEdit control
  with dmMain_u.dmMain do
  begin
    mtbMeta.Active := False;      //mtbMeta is my TFDMemTable
    mtbMeta.Filtered := False;
    mtbMeta.Filter := 'meta LIKE ' + QuotedStr('%' + metastr + '%');
    mtbMeta.Filtered := True;
    mtbMeta.Active := True;
  end;
end;

Can anyone here try to check my code if it is correct? Or I might need to do something else?


Solution

  • I would remove the .Active := False and .Active := True. They are the same as calls to .Close and .Open, and the Close will cause mtbMeta to lose its data.

    As for the slowness you mentioned in your comment, the usual way around that is to to something like this:

    procedure TformMain.edtSearchBoxChangeTracking(Sender: TObject);
    var
      metastr : string;
    begin
      Timer1.Enabled := True;
    end;
    

    and put your remaining code from your q into Timer1's OnTimer event. With its time interval set to say, 150 or 200 (millseconds), using the timer this way effectively waits until your typing "pauses for breath" as it were, rather than trying to update the gui on every keypress.