Fetch是SDK里自带的sample,描述了如何创建主细表结构并动态获取数据。
第一步,创建主细表。在schema中添加表orders和order details,回到客户端右击tbl_OrderDetails启动主细表向导:
选择
DataSource
和
MappingMode
:
点击
Next
选择描述主细表关系的字段
:
点击
Next
完成向导。这样第一步对表结构的构架就已经完成。
第二步,如何实现动态绑定表数据。
1,在主表orders里字段pa'rams设置StartingOrderID
![](https://img-my.csdn.net/uploads/201302/01/1359688535_8322.jpg)
2,打开schema,设置两个字段的属性一样
![](https://img-my.csdn.net/uploads/201302/01/1359688597_8343.jpg)
3,编辑tbl_orders事件afterScoll
procedure TClientForm.tbl_OrdersAfterScroll(DataTable: TDADataTable);
var
lrecordcount: integer;
begin
if fFetchRequired and DataTable.EOF and not DataTable.Fetching then
with DataTable do begin
ParamByName('StartingOrderID').AsInteger := FieldByName('OrderID').AsInteger;
MaxRecords := strtoint(edit1.text);
lrecordcount := DataTable.RecordCount;
LoadFromRemoteSource(True);
lrecordcount := RecordCount-lrecordcount;
fFetchRequired := lrecordcount = MaxRecords;
if not fFetchRequired then
MessageDlg(Format('Done fetching!!! Expected %d rows but only got %d ',
[MaxRecords, lrecordcount]), mtInformation, [mbOK], 0);
end;
end;
var
lrecordcount: integer;
begin
if fFetchRequired and DataTable.EOF and not DataTable.Fetching then
with DataTable do begin
ParamByName('StartingOrderID').AsInteger := FieldByName('OrderID').AsInteger;
MaxRecords := strtoint(edit1.text);
lrecordcount := DataTable.RecordCount;
LoadFromRemoteSource(True);
lrecordcount := RecordCount-lrecordcount;
fFetchRequired := lrecordcount = MaxRecords;
if not fFetchRequired then
MessageDlg(Format('Done fetching!!! Expected %d rows but only got %d ',
[MaxRecords, lrecordcount]), mtInformation, [mbOK], 0);
end;
end;
4,FILL按钮
procedure TClientForm.Button1Click(Sender: TObject);
begin
if not tbl_Orders.Active then begin
tbl_Orders.ParamByName('StartingOrderID').AsInteger := 0;
tbl_Orders.MaxRecords := strtoint(edit1.text);
fFetchRequired := True;
end;
tbl_Orders.Active := not tbl_Orders.Active
end;
begin
if not tbl_Orders.Active then begin
tbl_Orders.ParamByName('StartingOrderID').AsInteger := 0;
tbl_Orders.MaxRecords := strtoint(edit1.text);
fFetchRequired := True;
end;
tbl_Orders.Active := not tbl_Orders.Active
end;