Fast Report in Delphi 11. How to print each record based on the Quantity field of the record

154 Views Asked by At

I have a master Detail report. I want the report to print the master information (With its details) based on its quantity field. So if the Quanitty field of master record is 3 it should show up 3 times on the report if the Field is 2 it should come up 2 times etc.

-Here is an example of a Master table with 2 records

Master 1 Quantity field is 3, Master 2 Quantity Filed is 2

The desired Print is as follows:

Master1 Detail1

Master1 Detail1

Master1 Detail1

Master2 Detial2

Master2 Detail2

Any help would be greatly appreciated.

2

There are 2 best solutions below

1
Fabrizio On

You can do as follows:

  1. Add a master band and link it to the master dataset.
  2. Set the master band height to 0
  3. Add a detail band and put the fields from both master and detail datasets in this band

Picture showing the FastReport designer with a master band with 0 height, and a detail band

7
SergeGirard On

Use a FrxDBUserDataset FastReport Design Form Design and Run Code

procedure TForm16.Button1Click(Sender: TObject);
begin
frxreport1.ShowReport();
end;


// IMPORTANT  frxUserDetail.RangeEnd:=reCount
procedure TForm16.frxDBMasterFirst(Sender: TObject);
begin
frxUserDetail.First;
frxUserDetail.RangeEndCount:=FDMaster.FieldByName('QTE').AsInteger;
end;

procedure TForm16.frxDBMasterNext(Sender: TObject);
begin
frxUserDetail.First;
frxUserDetail.RangeEndCount:=FDMaster.FieldByName('QTE').AsInteger;
end;

My SQL data (Firebird) was

SELECT CAST('LIGNE 1' AS VARCHAR(20)) DESCRIPTION,3 QTE FROM RDB$DATABASE
UNION
SELECT CAST('LIGNE 2'  AS VARCHAR(20)),1 FROM RDB$DATABASE