MemdataSet | Filtered does not work lazarus / 16-Databases ---------------------------------------------------------------------- cpalx · 2015-04-27 21:54 What am i doing wrong? Code: [Select]var i: Integer; begin    with MemDataset1 do begin      FieldDefs.Add( 'id', ftInteger );      FieldDefs.Add( 'Nombre', ftString, 255);      Active:= true;      for i:= 0 to 200 do begin         Append;         FieldByName('id').AsInteger:= i;         FieldByName('nombre').AsString:= 'nombre_' + IntToStr( i );         Post;      end;   Filter:= 'Nombre = ''*11*'' ';   Filtered:= True;    end; Insert All the data but doesnt filter. (Do nothing) Lazarus 1.4 (Windows and linux) FPC : 2.6.4 ---------------------------------------------------------------------- howardpc · 2015-04-28 07:58 You are doing nothing wrong, simply not doing enough. You have to provide an OnFilterRecord handler, and then re-scan all the data so your display component picks up only what the new filter allows. Something like this: Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   SysUtils, memds, db, Forms, DBGrids, StdCtrls; type { TForm1 }   TForm1 = class(TForm)      dataSource: TDataSource;      dbGrid: TDBGrid;      MemDataset1: TMemDataset;      procedure FilterRecordHandler(DataSet: TDataSet; var Accept: Boolean);      procedure FormCreate(Sender: TObject);   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); var   i: integer; begin   with MemDataset1 do   begin     FieldDefs.Add( 'id', ftInteger );     FieldDefs.Add( 'Nombre', ftString, 255);     OnFilterRecord:=@FilterRecordHandler;     FilterOptions:=[foCaseInsensitive]; // change this to suit your requirements     Active:=True;     for i:= 0 to 200 do     begin       Append;       FieldByName('id').AsInteger:= i;       FieldByName('nombre').AsString:= 'nombre_' + IntToStr( i );       Post;     end;     Filter:='11';     Filtered:=True;     Close; // force a rescan of table data with filter in place     Open;   end; end; procedure TForm1.FilterRecordHandler(DataSet: TDataSet; var Accept: Boolean); begin   Accept:=Pos(DataSet.Filter, DataSet.FieldByName('Nombre').AsString) > 0; end; end. ---------------------------------------------------------------------- cpalx · 2015-04-28 18:05 Thanks