Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDatabaseDelphiRAD Studio

Powerful Filter Feature Allows Easily Dataset Filtering In Delphi With FireDAC

This sample demonstrates how to use the filter feature of TFDQuery.

To this end, the sample implements different preset filters. Moreover, you can edit your own filtering condition and apply the filter to a dataset in order to search for specific records.


You can find the Filter sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
    • Object PascalDatabaseFireDACSamplesComp LayerTFDQueryFilter
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

How to Use the Sample

  1. Navigate to the location given above and open Filter.dproj.
  2. Press F9 or choose Run > Run.


File in DelphiContains
The project itself.
The main form.


Before running the sample, the main components are configured at design time using the Object Inspector as follows:

  • TFDQuery object named qryWithFilter. This component is used to implement a dataset capable of executing SQL queries. The following setup is needed:
  • Configure the Connection property to specify the FireDAC connection object that is used to connect to a DBMS.
  • Set the SQL property to select * from {id Orders}. It specifies the SQL statement to execute for the query.
  • Set the Filtered property to True in order to active the filtering for the dataset.
  • TDataSource object named DataSource1. This component provides an interface between a dataset component and data-aware controls on a form. In this sample, it is used to provide communication between the dataset and the grid where the dataset is displayed. To this end, the DataSet property of DataSource1 is set to qryWithFilter, and the DataSource property of DBGrid1 is set to DataSource1.

When you run the application, click on the Use Connection Definition combo box and select an option in order to define a connection. When you select an item of the combo box, the sample uses the Open method of qryWithFilter in order to execute the SQL statement that retrieves the “Orders” table from the database. Then, the sample displays the “Orders” table using a TDBGrid component. Once the DBGrid1 is filled, you can interact with the sample in the following ways:

  1. Set a filter. Type your filter condition on the edit box and click on the Set button to apply the filter to the current dataset. For example: type ShipCountry='Spain' and press Set in order to see the records from the “Orders” table whose ShipCountry field is set to Spain.
  2. Use a preset filter. Click on the other buttons to see the results for different preset filters. For example: click on the Using BETWEEN button to see the records whose OrderID field is set between 10270 and 10280.

The link below will redirect you to the original post of the sample:


Head over and check out the full source code for the TFDQuery FireDAC filter sample for Delphi.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.