Im using this code to filter my table:
Table.Filtered := False;
Table.Filter := '[' + Field_Search + '] LIKE ''%' + Edit_Search.Text + '%''';
Table.Filtered := True;
but it raises this exception:
"Operation not applicable."
where is problem?
Im using this code to filter my table:
Table.Filtered := False;
Table.Filter := '[' + Field_Search + '] LIKE ''%' + Edit_Search.Text + '%''';
Table.Filtered := True;
but it raises this exception:
"Operation not applicable."
where is problem?
I found this topic looking for something else. I always use the TDataSet.OnFilterRecord event, and in most cases I use a TEdit.OnChange event so the search is "Active";
var
Criteria : string;
...
...
procedure TForm1.Edit1Change(Sender: TObject);
begin
Table.Filtered := False;
Criteria := Edit1.text;
Table.Filtered := True;
end;
and with the OnFilter event
procedure TForm1.TableFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
begin
Accept := AnsiContainsStr(Table.Fields[xx].asString,Criteria);
end;
Works for me.
The following Code will work as Like as well:
if Edit1.Text <>'' then
begin
Query1.Filter :='FieldName ='+quotedstr('*'+ edit1.Text +'*');
Query1.Filtered:=true;
end
else
begin query1.Filtered :=false; end;
I am using mostly with TEdit here is the code
if (EditSerarch.Text <> '') then
begin
FDQQuery.Filtered := false;
FDQQuery.Filter:= 'Name LIKE'+ QuotedStr('%'+EditSerarch.Text+'%') +
' OR Company LIKE '+ QuotedStr('%'+EditSerarch.Text+'%') +
' OR Phone LIKE '+ QuotedStr('%'+EditSerarch.Text+'%') +
' OR Mobile LIKE '+ QuotedStr('%'+EditSerarch.Text+'%');
FDQQuery.Filtered:= True;
end else FDQQuery.Filtered := false;