Recent

Author Topic: lazreport and master detail  (Read 10564 times)

chrgra

  • Jr. Member
  • **
  • Posts: 69
lazreport and master detail
« on: February 11, 2009, 10:17:53 pm »
Hello,

I'am able to make a report in lazreport. But I can't create a suitable master detail report. Looking in the forum and internet, I can't find something useable about this. Does someone has a sample or a simple explanation? Maybe a link I could not find?

Regards Chris Gradussen

DougNettleton

  • Jr. Member
  • **
  • Posts: 84
Re: lazreport and master detail
« Reply #1 on: February 13, 2009, 11:05:12 pm »
Chris:

If by "suitable" you mean forcing a page break on change of the master record, I can't help you - since I haven't figured that out yet.  But if you just want something like:

Page Header

master
  detail
  detail

master
  detail
  detail
  detail

etc

I did the following:

1) New Application:

2) Add ZConnection, ZQuery1, ZQuery2 - I use Firebird.
3) Add Datasource1, Datasource2

ZQuery1.SQL set to
  select fld1, fld2, fld3 from dbfile1 order by fld1
ZQuery2.SQL set to 
  select fld1, fld2, fld3 from dbfile1 where fld1 = :fld1
ZQuery2.DataSource := DataSource1

4) Add DBGrid1, DBGrid2
    - optional to see the relationship working.

5) Add frDBDataSet1, frDBDataSet2
frDataSet1.DataSet := ZQuery1
frDataSet2.DataSet := ZQuery2

6) Add frReport1, it didn't seem to matter which frDBDataSet I set the frReport1.DataSet to.

7) Add two buttons captions Design and Report with ...

procedure TForm1.Button1Click(Sender: TObject);
begin
  frReport1.LoadFromFile('MasterDetail.lrf');
  frReport1.DesignReport;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  frReport1.LoadFromFile('MasterDetail.lrf');
  frReport1.ShowReport;
end;

Right click on frReport1 choose Design Report

a) Add Page header band with some rectangle objects for titles, run date, run time and page number information

b) Add Master data band with some fields from ZQuery1

c) Add Detail data band with some fields from ZQuery2

d) save as 'MasterDetail.lrf'

The only problem I had was under some conditions no details displayed and if the details band was narrower the rectangle objects I put on it, the band moved around independent of the rectangle objects.

HTH,

Doug

chrgra

  • Jr. Member
  • **
  • Posts: 69
Re: lazreport and master detail
« Reply #2 on: February 14, 2009, 11:15:49 pm »
Thanks,

I saw lazreport as a different tool. But at first you have to set the relationship with masterdetail in the lazarus designer! (By the way, I did not use a parameter, but master detail relationship in lazarus/zeosdbo).

Testing page break: I just right click on the Master Data band and then I enable page break. So in my case every new department starts on a new page (the master data)

Regards Chris

slai

  • New Member
  • *
  • Posts: 25
Re: lazreport and master detail
« Reply #3 on: September 18, 2009, 08:48:32 pm »
Hy

I don't know if this thread is an actual question, but i solved this problem with a script.

If you have 2 associated fields betwen master and detail then you can use this script on the detail data band.

if [ZQueryDruck3."ID_PK"] = [ZQueryDruck4."ID_FK"] then
    DetailData1.Visible := True
else
    DetailData1.Visible := False

ID_PK = ID Primary Key
ID_FK = ID Foreign Key
« Last Edit: September 18, 2009, 08:50:27 pm by slai »