Skip to main content

Example: TcxDBDataFilterCriteria.OnBeforeChange

In this example, the TcxDBDataFilterCriteria.OnBeforeChange event is used to change the filter for the object of the query class from which data is retrieved.

The first two rows of the query specify:

SELECT *

FROM ORDERS.DB

In this event, the WHERE clause is added. AFilterText describes a condition to apply.

procedure TForm1.DBTableView1DataControllerFilterBeforeChange(
  Sender: TcxDBDataFilterCriteria; ADataSet: TDataSet;
  const AFilterText: String);
begin
  Query1.DisableControls;
  try
    Query1.Active := False;
    if AFilterText <> '' then
      //add condition to the query
      Query1.SQL[2] := 'WHERE ' + AFilterText;
    else
      Query1.SQL[2] := '';
    Query1.Active := True;
  finally
    Query1.EnableControls;
  end;
end;