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

Quickly Define Powerful Client-Side Aggregating Formulas With FireDAC Using TFDQuery In Delphi

This sample demonstrates how to define the client-side aggregating formulas with TFDQuery. You can find out more about aggregated fields and values in the Embarcadero DocWiki.

The fkAggregate aggregated fields management is similar to the expression calculated fields management. FireDAC calculates aggregated fields when TFDDataSet.AggregatesActive is set to True (by default, its value is set to False). The aggregated expression cannot be changed when the dataset is active. Also, the FireDAC application can use the TFDDataSet.Aggregates collection to define aggregated values. They are more light-weighted than fields and can be defined at any time, including when the dataset is active.

Location

You can find the Aggregates sample project at:

How to Use the Sample

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

Files

File in DelphiContains
Aggregates.dproj
Aggregates.dpr
The project itself.
fAggregates.pas
fAggregates.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 qryAggregates 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 an aggregate expression. Type your own aggregate expression on the Try edit box and press Enter for evaluation. For example: type MAX(Freight) and press Enter to see the maximum value of the Freight field on the Result edit box.
  2. Preset aggregate expressions. See the evaluation of the preset aggregate expressions.

The next link will guide you to the original post, on which you will find more detailed information, as well as other interesting links:

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

Head over and check out the full source code for the TFDQuery Aggregates sample on Embarcadero’s GitHub.

Exit mobile version