Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Learn How To Define Powerful Dataset Views Using Indices With FireDAC In Delphi Windows Development

The Indices sample shows you how to use the Indexes property of TFDQuery in order to specify a collection of indexes at design time and determine the data view of each index, including a sort order of the records. Moreover, you can sort the records on a specific field using the IndexFieldNames property. Click on a grid column title to sort its records at run time.

Location

You can find the Indices sample project at:

How to Use the Sample

  1. Navigate to the location given above and open Indices.dproj.
  2. Press F9 or choose Run > Run.
  3. Click on the Use Connection Definition combo box and select an option.
  4. Interact with the sample:
    • Click on the OrderBy combo box and select an option.
    • Click on any column title.

Files

File in DelphiContains
Indices.dproj
Indices.dpr
The project itself.
fIndices.pas
fIndices.fmx
The main form.

Implementation

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

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 qryMain 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. Choose a predefined index from the OrderBy combo box to set the predefined view of the dataset records.
  2. Click on a grid column title to sort its records:
    • One-click sorts the records in ascending order.
    • If the records are sorted in ascending order, and you click again, the sample sorts the records in descending order.
    • If the records are sorted in descending order, click again to undo the sorting of the dataset records.

For more details, check the link to the original post of Embarcadero:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.TFDQuery.Indices_Sample

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

With the use of Windows IDE, you can Quickly define dataset views using indices with FIREDAC when developing in Delphi or C++ environments. Try your Free Trial here.

Exit mobile version