我无法在运行时正确创建和填充 spring4d ObjectDataSet,异常说“字段 ID 没有数据集,(在设计时创建字段工作正常)这是我的代码:
procedure TForm2.FormCreate(Sender: TObject);
var
_id: TIntegerField;
_designation: TStringField;
_dataset: TObjectDataSet;
_artList: IList<TArticle>;
begin
_artList := TCollections.CreateList<TArticle>(true);
_artList.add(TArticle.Create(1, 'Article 1'));
_artList.add(TArticle.Create(2, 'Article 2'));
_artList.add(TArticle.Create(3, 'Article 3'));
_dataset := TObjectDataSet.Create(self);
_dataset.DataList := _artList as IObjectList;
_id := TIntegerField.Create(self);
_id.FieldKind := fkData;
_id.Name := 'fid';
_id.FieldName := 'ID';
_designation := TStringField.Create(self);
_designation.Size := 100;
_designation.FieldKind := fkData;
_designation.FieldName := 'Designation';
with _dataset.Fields do
begin
add(_id);
add(_designation);
end;
DataSource1.DataSet := _dataset;
// self.DBEdit1.DataField := 'ID';
// self.DBEdit2.DataField := 'Designation';
_dataset.Open;
_active := true;
end;