給你貼段代碼,其實至少有兩種方法可以實現你的功能.
下面是我寫的系統中實現了查詢從表的數據, 是其中之一
在主表的AfterScroll內查詢從表的數據.
GetDetailRecords()用來獲取從表的數據. 你可以直接寫代碼比如
commandtext:='select * from xxx_detail where code=' + 主表的主鍵
================
procedure TMasterData.OnAfterScroll(DataSet: TDataSet);
begin
if FBillOwner.DetailDataSet.Active then
begin
FBillOwner.Detail.GetDetailRecords();
FBillOwner.SetBillState;
end;
if Assigned(FBillOwner.DataObserver) then FBillOwner.DataObserver.SendNotify();
end;