FireDAC.Comp.DataSet.TFDDataSet.Indexes
Delphi
property Indexes: TFDIndexes read FIndexes write SetIndexes stored IsIS;
C++
__property TFDIndexes* Indexes = {read=FIndexes, write=SetIndexes, stored=IsIS};
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
property | public | FireDAC.Comp.DataSet.pas FireDAC.Comp.DataSet.hpp |
FireDAC.Comp.DataSet | TFDDataSet |
Description
Lists all client indexes that apply to the dataset.
Use Indexes to define client-side data views on the dataset records. Indexes are a collection of the TFDIndex objects, each of which defines optional:
- Sorting by fields (Fields, CaseInsFields, DescFields, Options).
- Sorting by expression (Expression, Options).
- Records filter (Filter, FilterOptions).
- Records distinction flag (Distinct).
The individual indexes are not just the sort and filter definitions. FireDAC maintains a consistent view on the data for each active index, while the application fetches data or edits data. That creates additional overhead, but allows to switch between indexes without delays.
To make a view current, set its Selected property to True or set the dataset's IndexName property to the view name.
Note: The view must have its Active property set to True to be maintained.
The dataset maintains Indexes views when IndexesActive is True. When an application needs to perform batch updates to the dataset, set IndexesActive to False before updating, and return to the original value after updating. Also, see the BeginBatch and EndBatch methods.
Setting IndexFieldNames does not add a TFDIndex object to the Indexes collection. Defining IndexDefs before opening the dataset clears Indexes and fills them using IndexDefs information. So, there are two alternative ways: either use IndexDefs or use Indexes. We suggest to use Indexes, as it is more flexible.
Some of the navigation methods, such as Locate, LocateEx, Lookup, LookupEx, SetRange, use indexes to optimize their operations.
The sorting and filter expressions in Indexes supports extended expression syntax.
Example
with FDMemTable1.Indexes.Add do begin
Name := 'by_name';
Fields := 'NAME;DT';
Active := True;
end;
with FDMemTable1.Indexes.Add do begin
Name := 'by_payments';
Expression := 'sum(sal + bonus)';
Filter := 'dep_id is not null;
Active := True;
end;
FDMemTable1.IndexesActive := True;
FDMemTable1.IndexName := 'by_name';
See Also
- Sorting Records
- Writing Expressions
- FireDAC.Comp.DataSet.TFDDataSet.IndexDefs
- FireDAC.Comp.DataSet.TFDDataSet.IndexesActive
- FireDAC.Comp.DataSet.TFDDataSet.IndexFieldNames
- FireDAC.Comp.DataSet.TFDDataSet.IndexName
- FireDAC.Comp.DataSet.TFDDataSet.BeginBatch
- FireDAC.Comp.DataSet.TFDDataSet.EndBatch
Samples
- FireDAC TFDQuery Indices sample