Delphi FireDAC datasets offer a quick and easy sorting feature, through the property “IndexFieldNames” in which you list the field names to use as an index, and you can optionally specify sorting options for each field.
This property is an alternative for creating and setting indexes for a dataset in the property “IndexName”.
Note that “IndexFieldNames” and “IndexName” properties are mutually exclusive, so setting one property will clear the other.
How to use it
- Whether in the object inspector or through code, you specify the name of each field for indexing the dataset, separated with semi-colons.
- Field names order is significant for the sort.
- Optionally, you can specify the sort options for any field in your list, by using the following syntax explained in the table below :
fieldname[:[D][A][N]]
D | Use descending sorting on this field |
A | Use ascending sorting on this field |
N | Use case-insensitive sorting on this field |
Examples
Using many fields for sorting with no options :
FDMemTable1.IndexFieldNames := 'Speciality;Subject;Title;Author;Publisher;Year';
Setting options for a field :
FDQuery1.IndexFieldNames := 'order_date:D;customer_name:N';