Ime,在包含 fkInternalCalc 字段的复合索引上索引 ClientDatasSet 工作正常。
下面的代码在 D7 和 XE6 中工作,并且与 Midas.Dll 版本相隔十年,给出
因此,除非 XE2 中存在某种回归,否则我会怀疑报告的问题出在 OP 端。
// 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;