我创建分组的动态报表的得代码如下。编译和运行无错,但是没有出现分组的情况,显示的结果和不分组差不多(只是不出现组标头)。 frReport1.Pages.Clear;
frReport1.Pages.Add; // create page
Page := frReport1.Pages[0];
frdbdataset1.DataSet:=dm.dts_salary;
b := TfrBandView.Create; // create Title band
b.SetBounds(0, 20, 0, 79); // position and size in pixels
b.BandType := btReportTitle; // (only Top and Height are significant
Page.Objects.Add(b); // for the band) v := TfrMemoView.Create; // create memo
v.SetBounds(20, 60, 300, 23);
v.BandAlign := baWidth;
v.Prop['Alignment'] := frtaCenter; // another way to access properties
v.Prop['Font.size'] := 14;
v.Prop['Font.name'] := '隶书';
v.Memo.Add('公司'+inttostr(u_main.pub_year)+'年'+inttostr
(u_main.pub_month)+'月'+'工资表');
Page.Objects.Add(v); DocMode := dmDesigning;
b := TfrBandView.Create;
b.SetBounds(0, 100, 800, 22);
b.BandType := btgroupheader;//标题表头
b.Prop['formnewpage'] := True;
b.name:='groupheader1';
b.Prop['condition'] :='[dm.dts_salary."name"]';
//b.GroupCondition:='[]';
page.Objects.Add(b); v:=TfrMemoView.Create; // create memo
v.SetBounds(25, 101, 65, 15);
v.Memo.Text:='姓名';
//v.Parent.Name:='groupheader1';
v.Prop['Font.size'] := 10;
v.Prop['Font.name'] := '宋体';
Page.Objects.Add(v); b := TfrBandView.Create;
b.SetBounds(0, 125, 700, 20);
b.BandType := btMasterData; //主项数据
b.Dataset := 'frDBDataSet1';
page.Objects.Add(b);
i:=1;
while a_field_no[i]<>'' do
begin
v := TfrMemoView.Create; // create memo
v.SetBounds(25+65*(i-1), 126, 65, 15);
v.Memo.Add('[dm.dts_salary.'+'"'+a_field_no[i]+'"'+']');
v.Prop['Font.size'] := 10;
v.Prop['Font.name'] := '宋体';
Page.Objects.Add(v);
i:=i+1;
end;
frReport1.ShowReport;
frReport1.Pages.Add; // create page
Page := frReport1.Pages[0];
frdbdataset1.DataSet:=dm.dts_salary;
b := TfrBandView.Create; // create Title band
b.SetBounds(0, 20, 0, 79); // position and size in pixels
b.BandType := btReportTitle; // (only Top and Height are significant
Page.Objects.Add(b); // for the band) v := TfrMemoView.Create; // create memo
v.SetBounds(20, 60, 300, 23);
v.BandAlign := baWidth;
v.Prop['Alignment'] := frtaCenter; // another way to access properties
v.Prop['Font.size'] := 14;
v.Prop['Font.name'] := '隶书';
v.Memo.Add('公司'+inttostr(u_main.pub_year)+'年'+inttostr
(u_main.pub_month)+'月'+'工资表');
Page.Objects.Add(v); DocMode := dmDesigning;
b := TfrBandView.Create;
b.SetBounds(0, 100, 800, 22);
b.BandType := btgroupheader;//标题表头
b.Prop['formnewpage'] := True;
b.name:='groupheader1';
b.Prop['condition'] :='[dm.dts_salary."name"]';
//b.GroupCondition:='[]';
page.Objects.Add(b); v:=TfrMemoView.Create; // create memo
v.SetBounds(25, 101, 65, 15);
v.Memo.Text:='姓名';
//v.Parent.Name:='groupheader1';
v.Prop['Font.size'] := 10;
v.Prop['Font.name'] := '宋体';
Page.Objects.Add(v); b := TfrBandView.Create;
b.SetBounds(0, 125, 700, 20);
b.BandType := btMasterData; //主项数据
b.Dataset := 'frDBDataSet1';
page.Objects.Add(b);
i:=1;
while a_field_no[i]<>'' do
begin
v := TfrMemoView.Create; // create memo
v.SetBounds(25+65*(i-1), 126, 65, 15);
v.Memo.Add('[dm.dts_salary.'+'"'+a_field_no[i]+'"'+']');
v.Prop['Font.size'] := 10;
v.Prop['Font.name'] := '宋体';
Page.Objects.Add(v);
i:=i+1;
end;
frReport1.ShowReport;
姓名
张三 男
姓名
李四 女
.............
但是以上代码显示的是:
张三 男
李四 女
......
要有分组栏的么,不然怎么分组
v.SetBounds(25+65*(i-1), 126, 65, 15);
v.Memo.Add('[dm.dts_salary.'+'"'+a_field_no[i]+'"'+']');//这就是分栏数据
v.Prop['Font.size'] := 10;
v.Prop['Font.name'] := '宋体';
Page.Objects.Add(v);
不是分组数据栏
要建立分组栏:
c := TfrBandView.Create;
c.SetBounds(0, 125, 700, 20);
c.BandType := 分组栏; //具体怎么写,自己查查
以下加入数据
b := TfrBandView.Create;
b.SetBounds(0, 100, 800, 22);
b.BandType := btgroupheader;//
b.Prop['formnewpage'] := True;
b.name:='groupheader1';
b.Prop['condition'] :='[dm.dts_salary."name"]'; //此处为分组字段
//b.GroupCondition:='[]';
page.Objects.Add(b);