Yes, it is possible. Just use the indexes offered by the DataSet.
I find it interesting to address a bit about the indexes:
There are basically two types of indices in Delphi: Temporary and persistent .
Temporary indices are created using IndexFieldNames. Let's say you have a ClientDataSet with the fields: FirstName, LastName and DateNation. If I want to sort my records by the last name and then the first one, I could do this:
ClientDataSet1.IndexFieldNames := 'UltimoNome;PrimeiroNome';
At any time this can be changed.
ClientDataSet1.IndexFieldNames := 'UltimoNome';
// etc...
When you do this, delphi creates the indexes internally and associates them with the dataset. So they are called temporary .
In your case this will not serve you, I wrote only for enrichment. In your case a persistent index will be more appropriate:
Persistent indexes are created in the IndexDefs of your DataSet. So you can, for each index, define a series of properties. They are used in the same way as temporary indexes, just use the name given to the persistent index when they are created in design-time.
To create a Persistent Index in RunTime, just use the code snippet below:
with ClientDataSet1.IndexDefs.AddIndexDef do
begin
Name := 'OrdenarUltimoPrimeiroNomedx';
Fields := 'UltimoNome;PrimeiroNome';
Options := [ixDescending, ixCaseInsensitive];
end;
ClientDataSet1.IndexName := 'OrdenarUltimoPrimeiroNomedx';
EDIT: I talked so much and I did not give an exact answer.
You can create as many persistent indexes as you need:
with ClientDataSet1.IndexDefs.AddIndexDef do
begin
Name := 'OrdenarUltimoPrimeiroNomedx';
Fields := 'UltimoNome;PrimeiroNome';
Options := [ixDescending, ixCaseInsensitive];
end;
with ClientDataSet1.IndexDefs.AddIndexDef do
begin
Name := 'DataNascimentoAscdx';
Fields := 'DataNascimento';
Options := [ixAscending];
end;
ClientDataSet1.IndexName := 'DataNascimentoAscdx;OrdenarUltimoPrimeiroNomedx';
In the above example I will sort by the Ascending birth date and then by the Last Name and First Descending Name.
If you want a good reference, I suggest you visit this link :