Ime, indexing a ClientDatasSet on a compound index including an fkInternalCalc field works fine.
The code below works in D7 and XE6, and with Midas.Dll version ten years apart, giving
So, unless there was some kind of regression in XE2, I would suspect the problem reported
was in something at the OP's end.
// tested with:
// midas.dll 7.1.1692.668 30 August 2004
// midas.dll 20.0.16277.1276 16 June 2014
procedure TForm1.SetUp;
var
Field : TField;
i : Integer;
begin
Field := TIntegerField.Create(Self);
Field.FieldName := 'PatNo';
Field.FieldKind := fkData;
Field.Index := 0;
Field.DataSet := CDS;
Field := TBooleanField.Create(Self);
Field.FieldName := 'HighLight';
Field.FieldKind := fkInternalCalc;
Field.Index := 1;
Field.DataSet := CDS;
CDS.OnCalcFields := CDSCalcFields;
CDS.CreateDataSet;
for i := 1 to 10 do begin
CDS.Insert;
CDS.FieldByName('PatNo').AsInteger := i;
CDS.Post;
end;
end;
procedure TForm1.CDSCalcFields(DataSet: TDataSet);
var
Value : Integer;
begin
Value := DataSet.FieldByName('PatNo').AsInteger;
DataSet.FieldByName('Highlight').AsBoolean := Odd(Value);
end;
const
scIndexName = 'PatNo';
scHighlight = 'Highlight';
procedure TForm1.AddHLIndex;
var
IndexDef : TIndexDef;
begin
IndexDef := TIndexDef.Create(CDS.IndexDefs, scIndexName, 'Highlight;PatNo', [ixDescending]);
IndexDef.DescFields := scHighlight;
CDS.IndexName := scIndexName;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AddHLIndex;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetUp;
end;
fkInternalCalc
which according to threads.embarcadero.com/threads/threads.exe/… can be used in an index – BivalentOnCalcField()
to be executed? I can not callRefresh()
because my client dataset is not attached to any provider. The only way I have found was to callResync([]);
to force recalculation of all calculated fields. – BivalentIndexFieldNames
instead of a predefined index, but the problem persists. – Bivalent