How to show data at Fast Report in 3*3 grid format?

a 夏天 提交于 2019-11-29 12:40:23

EDIT since the previous* answer does not work with newer versions

Set rowcount to 9 for your masterdata band of the subreport.
In your mainreport, copy the masterdata band containing the subreport and insert it twice.
Put a headerband between the masterbands with property StartNewPage set to true.
Add OnBeforePrint events to the second and the third subreport to change the filter for the dataset.

procedure Subreport2OnBeforePrint(Sender: TfrxComponent);
begin
  TfrxDBDataSet(Report.GetDataset('frxDBDataset1')).Dataset.Filter := 'ID>9';  
  TfrxDBDataSet(Report.GetDataset('frxDBDataset1')).Dataset.Filtered := true;                                          
end;

procedure Subreport3OnBeforePrint(Sender: TfrxComponent);
begin
  TfrxDBDataSet(Report.GetDataset('frxDBDataset1')).Dataset.Filter := 'ID>18';  
  TfrxDBDataSet(Report.GetDataset('frxDBDataset1')).Dataset.Filtered := true;  
end;

(*) for older report versions, you can use an other approach, which stopped working between the versions 4.10.01 and 4.12.14.

Add an OnAfterPrint event to your memo on the subreport. Set the property StartNewPage to true after printing 9 "lines", Rowcount of the Masterband has to set to 1.

procedure YourMemoFromTheSubReportToRepeat9TimesPerPageOnAfterPrint(Sender: TfrxComponent);
begin
    MasterDataBandFromSubReport.StartNewPage := <Line#>  mod 9 = 0  
end;

Public variable declarations

  public
    i: integer;
    myid: Array Of Integer;
    mydesc: Array Of String;
    k: Integer;
    rowcount: Integer;

Code at FormCreate event

begin
    i := 0;
    k := 0;
    UniTable1.SQL.Text := 'Select * from userplays';
    UniTable1.Execute;
    rowcount := UniTable1.RecordCount;
    SetLength(myid, rowcount);
    SetLength(mydesc, rowcount);

      while not UniTable1.Eof do
      begin
         myid[k] := UniTable1.FieldByName('id').Value;
         mydesc[k] := UniTable1.FieldByName('description').Value;
         UniTable1.Next;
         inc(k);
      end;
end.

Code at OnGetValue event of the frxReport

var
  j: Integer;

begin
 j := i div 2;
 if j < rowcount then
   begin

     if (VarName = 'ID1') then
       Value :=  myid[j];

     if (VarName = 'DESC1') then
       Value :=  mydesc[j];

   end
 inc(i);

Above ID1 and DESC1 are two variable declared at frxReport memo, value assigned to it at OnGetValue event with the help of global Array myid & mydesc. Global arrays myid & mydesc are filled with database field values at FormCreate event.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!