//先在窗体上添加: //ClientDataSet1、DataSource1、DBGrid1、ClientDataSet2、DataSource2、DBGrid2; 然后:procedure TForm1.FormCreate(Sender: TObject);begin { 关联数据集 } DBGrid1.DataSource := DataSource1; DataSource1.DataSet := ClientDataSet1; DBGrid2.DataSource := DataSource2; DataSource2.DataSet := ClientDataSet2; { 载入范例文件 } ChDir(GetEnvironmentVariable('COMMONPROGRAMFILES') + '\CodeGear Shared\Data\'); ClientDataSet1.LoadFromFile('orders.xml'); ClientDataSet2.LoadFromFile('items.xml'); { 设定主从表 } ClientDataSet2.MasterSource := DataSource1; ClientDataSet2.MasterFields := 'OrderNo'; { 多个字段时用分号隔开 }end;
联系客服