参考https://www.cnblogs.com/qiufeng2014/p/17388138.html
链接:https://pan.baidu.com/s/1ayzgDbXjgXBnw-jM1FR4gA
提取码:ogqz
unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, memds, db, Forms, Controls, Graphics, Dialogs, DBGrids; type { TForm1 } TForm1 = class(TForm) DataSource1: TDataSource; DBGrid1: TDBGrid; MemDataset1: TMemDataset; procedure FilterRecordHandler(DataSet: TDataSet; var Accept: Boolean); procedure FormCreate(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FilterRecordHandler(DataSet: TDataSet; var Accept: Boolean); begin Accept:=Pos(DataSet.Filter, DataSet.FieldByName('Nombre').AsString) > 0; end; 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:='2'; //这里添加 过滤条件 Filtered:=True; Close; // force a rescan of table data with filter in place Open; end; end; end.
标签:begin,end,TForm1,DataSet,filter,lazarus,memdataset,var,procedure From: https://www.cnblogs.com/tulater/p/18054107