Good @LuizVichiatto, as promised
in the previous response comment I did an example
which works perfectly.
Step 1: Put a DataSource, DbGrid, Edit and a DataSet in my Form in my case I used the ClientDataSet, but it could be any other one that supports the Filter property.
Step 2: Set the events as below
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBClient, Grids, DBGrids;
type
TForm1 = class(TForm)
cdsBusca: TClientDataSet;
EditBusca: TEdit;
Label1: TLabel;
cdsBuscaNome: TStringField;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure FormCreate(Sender: TObject);
procedure EditBuscaChange(Sender: TObject);
procedure cdsBuscaFilterRecord(DataSet: TDataSet; var Accept: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
cdsBusca.CreateDataSet;
cdsBusca.Append;
cdsBuscaNome.Value := 'Monica';
cdsBusca.Append;
cdsBuscaNome.Value := 'Eduardo';
cdsBusca.Append;
cdsBuscaNome.Value := 'Renato Russo';
cdsBusca.Post;
end;
procedure TForm1.EditBuscaChange(Sender: TObject);
begin
cdsBusca.Filtered := False;
cdsBusca.Filter := '';
cdsBusca.Filtered := True;
end;
procedure TForm1.cdsBuscaFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
begin
if EditBusca.Text = '' then
begin
cdsBusca.Filtered := False;
Exit;
end;
Accept := Pos(EditBusca.Text, cdsBuscaNome.AsString) > 0;
end;
end.
HereIaddedthenameEdmilson,onlytofiltereverythingthatcontainedtheletter"AND"