I'm trying to do the sorting on a lookup fields the way like you mentioned (make an InternalCalc field). But something always goes wrong.
I have a LookUp field (called NameField) and a CalcField (NameCalcField). In the ClientDataSet's OnCalcFields event I do the following:
DataSet.FieldByName ('NameCalcField').AsString:=DataSet.FieldByName ('NameField').AsString;
Then I add an index to that calculated field and set the index for the ClientDataSet, but I always got the original order back, when the index was created.
For example:
Before the index creation:
FieldA NameField NameCalcField
3 B B
1 C C
2 A A
Now I create an Index on NameCalcField.
After that I sort it by "FieldA": ClientDataSet.IndexFieldNames:='FieldA';
It works.
FieldA NameField NameCalcField
1 C C
2 A A
3 B B
Now I tell the CDS to use the Index that I've created:
ClientDataSet.IndexFieldNames:='';
ClientDataSet.IndexName:='Index1';
The result is:
FieldA NameField NameCalcField
3 B B
1 C C
2 A A
The original one. The order should be "ABC".
What am I doing wrong?
Thanks!