FireDAC.TFDQuery.Filter Sample

From RAD Studio Code Examples
Jump to: navigation, search

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

Location

You can find the Filter sample project at:

Description

The Filter sample shows you how to use the Filter property of TFDQuery to specify a dataset filter. 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.

Note: When filtering is applied to a dataset, only those records that meet the filtering conditions are available. The Filter property describes the filtering condition.

How to Use the Sample

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

Files

File in Delphi Contains

Filter.dproj
Filter.dpr

The project itself.

fFilter.pas
fFilter.fmx

The main form.

Implementation

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

  • A 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.
  • A 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.

Uses

See Also

Samples

Personal tools
Assistance