FireDAC.Comp.DataSet.TFDDataSet.Indexes

From RAD Studio API Documentation
Jump to: navigation, search

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:

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

Samples