我有TDataModule
个TADOQueries
& 2个数据源:主数据和详细信息。
DataModule.DetailQuery.Datasource := MasterQueryDataSource;
我以单独的形式显示这些查询中的数据集。每次都会创建一个新的表单实例。表单有MasterDbGridEh和DetaildbGridEh绑定到master和details数据源。当用户完成编辑时,表单将被销毁,查询将被关闭。当用户下次需要打开窗口时,会创建一个新实例并激活查询。
当第一次调用表单时,每个工作都很好。 但是我第二次使用DetailsDbGridEh来解决这个问题: 它显示选择了第一行的DataSet,但是当我尝试滚动时,我无法在网格中向上或向下移动。在向数据集追加新行后,不会显示新行。 当我尝试向上或向下移动并且数据集实际在幕后滚动但是滚动和dbgrideh不显示更改时,数据集AfterScroll事件触发。 似乎在首次显示数据集之后,dbgrid以某种方式失去了对数据源的触摸。
UPDATE 查询结构: Datamodel由实体组成:ORDER,每个订单由几个JOBS组成,每个Job有几个参与者。 所以有3个查询:OrderEditQuery,JobEditQuery和JobParticipantsQuery; JobEditQuery依赖于OrderEditQuery,并且具有从ORDEREDITQUERY获取的参数ORDER_ID JobParticipantsQuery依赖于JobEditQuery,并且具有从JobEditQuery获取的参数JoB_ID。
当打开JobEditorForm时,只编辑了一个订单,但用户应该能够浏览和编辑订单的作业,并通过和编辑每个作业的参与者
CODE:
以主窗体形式调用编辑器表单的代码:
with TJobEditorForm.Create(Self, orderID, // constructor
jobID, officeID) do
begin
ShowModal;
end;
构造
constructor TJobEditorForm.Create(AOWner: TComponent; orderID: integer;
jobID: integer; officeID: integer);
begin
self.Create(AOwner);
_orderID := orderID;
_startingJobID := jobID;
_officeID := officeID;
end;
在表格上显示:
procedure TJobEditorForm.FormShow(Sender: TObject);
begin
jobEditDataModule.ActivateQueries(_orderID, _officeID);
// jobEditdatamodule is the datamodule where the queries sit
end;
procedure TJobEditDataModule.ActivateQueries(orderID, officeID : integer);
begin
CloseQueries; // put this in to ensure that all queries are closed before they are reopened
// different auxiliary queries used for look up fields
Data.VID_ALL.Active := false;
Data.VID_ALL.Parameters.ParamValues['office'] := officeID;
Data.VID_ALL.Active := true;
Data.KOEF_ALL.Active := false;
Data.KOEF_ALL.Parameters.ParamValues['podr'] := officeID;
Data.KOEF_ALL.Active := true;
Data.Jobstatuses_All.Active := true;
Data.Attract_Channels_All.Active := true;
JobEditDataModule.Customers.Active := true;
EmployeeDataModule.Employees.Active := true;
// this is the query that gives me trouble
JobParticipantsQuery.Active := false;
// main query
OrderEditQuery.Parameters.ParamValues['orderID'] := orderID;
OrderEditQuery.Open;
OrderEditQuery.EnableControls;
// first details query. Dependent on OrderEditQuery (takes two params: officeID and OrderID. OrderID is taken from OrderEditQuery, on which JobEditQuery depends)
JobEditQuery.Active := false;
JobEditQuery.EnableControls;
JobEditDataModule.JobEditQuery.Parameters.ParamValues['officeID'] := officeID;
TDataUtils.EnsureActive( [ JobEditQuery ]);
JobEditQuery.EnableControls;
// JobPArticipantsQuery is details query dependent on JobEditQuery.
JobparticipantsQuery.DisableControls;
JobparticipantsQuery.EnableControls;
JobParticipantsQuery.Active := true;
JobparticipantsQuery.EnableControls;
end;
关闭编辑器表单后,将执行CloseQueries过程:
procedure TJobEditDataModule.CloseQueries;
begin
OrderEditQuery.DisableControls;
JobParticipantsQuery.DisableControls;
JobparticipantsQuery.DisableControls;
JobParticipantsQuery.Close;
JobEditQuery.Close;
OrderEditQuery.Close;
end;