看看我代码,看看有什么问题吧:
QueryStr := 'MasterQuery';
MasterQuery.Close;
MasterQuery.SQL.Text := 'select * from prj';//prj和subPrj表中共有一个MarkId字段
MasterQuery.Prepare;
MasterQuery.Open;
//建立了明细表中的主表条,主数据项---------------
curY:=100;
CellHeight:=36;
curX := Page.pgMargins.Left;
curY := CurY + cellheight + 5;
pagew := Page.PrnInfo.Pgw;
pageh := Page.PrnInfo.Pgh;
prnpagew := pagew - Page.pgMargins.Right - Page.pgMargins.Left;
prnpageh := pageh - Page.pgMargins.Bottom - Page.pgMargins.Top;
b := TfrBandView.Create;
// create MasterData band
b.SetBounds(curX, curY, prnpagew, cellheight);
b.BandType := btMasterData;
b.Dataset := 'frDBMasterDataSet';
// band's dataset
b.Name := 'MasterData';
b.Prop['Stretched'] := true;
Page.Objects.Add(b);
/// 主要数据内容
// create data field
For i := 1 To 5do
begin
v := TfrMemoView.Create;
cellwidth := 60;
v.SetBounds(curX, CurY, cellwidth, cellheight);
CurX := CurX + cellwidth;
v.Memo.Add(ColumnStr);//这里放主表中的数据,columnStr格式如:'[MasterQuery."字段名"]';
//SetMemoView(v);//一个设置样式的函数,
v.FillColor:=clSilver;
Page.Objects.Add(v);
end;
//---------下面是设置从表---细数据项-----------
QueryStr := 'DetailQuery';
DetailQuery.Close;
DetailQuery.SQL.Text := 'select * from Subprj where MarkId=:MarkId';
DetailQuery.ParamByName('MarkId').AsInteger := MasterQuery.FieldValues['MarkId'];
DetailQuery.Prepare;
DetailQuery.Open;
//这里添加每一条主表的细项
curX := Page.pgMargins.Left;
CurY := CurY + CellHeight+5;
b := TfrBandView.Create;
// create MasterData band
b.BandType := btDetailData;
b.Dataset := 'frDBDetailDataSet';
// band's dataset
b.Name := 'DetailBand';
b.Prop['Stretched'] := true;
b.SetBounds(curX, curY, prnpagew, cellheight);
Page.Objects.Add(b);
/// 主要数据内容
// create data field
For i := 1 To 5do
begin
v := TfrMemoView.Create;
cellwidth := 60;
v.SetBounds(curX, CurY, cellwidth, cellheight);
CurX := CurX + cellwidth;
v.Memo.Add(ColumnStr);//这里放主表中的数据,columnStr格式如:'[MasterQuery."字段名"]';
//SetMemoView(v);
v.FillColor:=clSilver;
Page.Objects.Add(v);
end;
frReport1.ShowReport;//打印预览