Lazarus

Programming => Packages and Libraries => LazReport => Topic started by: Pabdym on September 26, 2012, 05:52:50 pm

Title: LazReport : How to use TfrCompositeReport ?
Post by: Pabdym on September 26, 2012, 05:52:50 pm
Hi,

Code: [Select]
for i := 1 to 36 do begin
   sgEL.Row := i;
   frReport1.LoadFromFile(gsReportPath+myReport.lrf');
   frReport1.PrepareReport;  {from Rows[i]}
   frCompositeReport1.Reports.add(frReport1);
end;
frCompositeReport1.ShowReport;

frCompositeReport1 contains 36  pages but the same (the last one). How is it necessary to proceed?
                                   
Thanks
Title: Re: LazReport : How to use TfrCompositeReport ?
Post by: jesusr on September 26, 2012, 10:58:14 pm
It looks like it has 36 copies of the same report.

try

Code: [Select]
var
  r: TfrReport;
for i := 1 to 36 do begin
   sgEL.Row := i;
   r:=TfrReport.create(self);
   r.loadFromFile(gsReportPath+'myReport.lrf'); // here myReport.lrf must be the report corresponding to Row "i"
   frCompositeReport1.Reports.add(r);
end;
frCompositeReport1.ShowReport;

Just like is demostrated in the lazarus/components/lazreport/samples/editor sample project.
Title: Re: LazReport : How to use TfrCompositeReport ?
Post by: Pabdym on September 27, 2012, 12:54:12 pm
I tried your code : 36 empty pages.

Thus, I tried :
Code: [Select]
type
TForm1 = class(TForm)     
 Filas: TfrUserDataset;   
 frCompositeReport1: TfrCompositeReport;       
 [...]
 procedure TheReportEnterRect(Memo: TStringList; View: TfrView);
 procedure TheReportGetValue(const ParName: String; var ParValue: Variant);
 [...]
end;

procedure TForm1.Button12Click(Sender: TObject);
var
i : integer;
begin

  with frCompositeReport1 do begin
    DoublePass:= True;
    Reports.Clear;
  end;
  for i := 1 to 36 do begin
   sgEL.Row := i;
   TheReport :=TfrReport.Create(self);
   TheRepor.OnEnterRect:= @TheReportEnterRect;
   TheReport.OnGetValue:= @TheReportGetValue;
   TheReport.Dataset := Filas;
   TheReport.loadFromFile(gsReportPath+'myReport.lrf');
   //TheReport.PrepareReport;
   //TheReport.ShowReport; {The 36 pages are OK}
   frCompositeReport1.Reports.add(TheReport);
end;
frCompositeReport1.ShowReport;

It always looks like it has 36 copies of the same report (the last page). With ' TheReport.PrepareReport + TheReport.ShowReport ', each of the reports 'TheReport' is correct.

I also tried :
Code: [Select]
var  TheReport : array [1..100] of TfrReport;
begin
for i := 1 to 36 do begin
   sgEL.Row := i;
   TheReport[i]:=TfrReport.Create(self);
   TheReport[i].OnEnterRect:= @TheReportEnterRect;
   TheReport[i].OnGetValue:= @TheReportGetValue;
   TheReport[i].Dataset := Filas;
   TheReport[i].loadFromFile(gsReportPath+'myReport.lrf');
 //  TheReport[i].PrepareReport;
 //  TheReport[i].ShowReport;         {It's OK}
   frCompositeReport1.Reports.add(TheReport[i]);
   TheReport[i].Free;
end;
frCompositeReport1.ShowReport;
   

After the last " TheReport(i).Free;" --> Exception class 'External : SIGSEGV'.

Without 'TheReport(i).Free;', the result is the same: 36 identical pages (the last one). With ' TheReport(i).PrepareReport + TheReport(i).ShowReport ',  each of the reports 'TheReport(i)' is also correct.


TinyPortal © 2005-2018