Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-05

Lazreport master-detail on one line

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Koenraad Lelong

Hi,

I want to make a report of database data. The data has a master-detail relationship. For every master-record there are a fixed number of detail-records.
A detail record = ItemCode, ItemValue

So I make a lazreport. I put a masterheader band on the report and I put some text on it. Then I put a masterdata band on the report and I put some rectangle objects on that band and connect those the master-table. When I show the report, everything is like I want it. Next step is to add detail-fields. I though that using a cross-data band was the needed tool. On the crossing of the masterheader-band I put a rectangle-object and couple this to the detail-field ItemCode. On the crossing of the masterdata-band I put a rectangle-object coupled to the detail-field ItemValue.

When I now show the report, my master-information is OK, for all master-records, but the detail-information is that of the first detail-record, for all master-records. Also the information of the detail in the master-header is OK.
I have two grids showing the master-detail information so I know my queries are OK.

What am I doing wrong ?
Enclosed a screenshot. Green ovals contain correct data, the red oval contains bad data.

Koenraad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lazarus2.png
Type: image/png
Size: 104384 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140522/c49a0710/attachment-0001.png>

Reply by email

Koenraad Lelong

Hi,

I want to make a report of database data. The data has a master-detail relationship. For every master-record there are a fixed number of detail-records.
A detail record = ItemCode, ItemValue

So I make a lazreport. I put a masterheader band on the report and I put some text on it. Then I put a masterdata band on the report and I put some rectangle objects on that band and connect those the master-table. When I show the report, everything is like I want it. Next step is to add detail-fields. I though that using a cross-data band was the needed tool. On the crossing of the masterheader-band I put a rectangle-object and couple this to the detail-field ItemCode. On the crossing of the masterdata-band I put a rectangle-object coupled to the detail-field ItemValue.

When I now show the report, my master-information is OK, for all master-records, but the detail-information is that of the first detail-record, for all master-records. Also the information of the detail in the master-header is OK.
I have two grids showing the master-detail information so I know my queries are OK.

What am I doing wrong ?
Enclosed a screenshot. Green ovals contain correct data, the red oval contains bad data.

Koenraad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lazarus2.jpg
Type: image/jpeg
Size: 49562 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140526/698fd2ab/attachment-0001.jpg>

Reply by email

Reinier Olislagers
to Koenraad Lelong

(Note: haven't ever set up master/detail reporting in Lazreport, so just some ideas below)

At least in other reporting solutions, master details means having some master band, then a detail band below it.
This gives the following setup:
Master1 record
...detail1:record1
...detail1:record2
...
...detail1.recordn
Master2 record
...detail2:record1
...
...detail2:recordn1

In other words, it supports single row reports only. No idea if this applies to lazreport.

In other reporting solutions, if you want to have master+detail info next to each other, you can use a query in the database that provides the info in the desired layout.

This is often known as s acrosstab query, searching gives e.g. Postgresql
http://stackoverflow.com/questions/3002499/postgresql-crosstab-query Or
http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=25

Obviously no idea if this applies to lazreport as well.

Reply by email

Giuliano Colla
to Koenraad Lelong: I want to make a report of database data. The data has a master-detail relationship. For…

Il 26/05/2014 13:26, Koenraad Lelong ha scritto:

Show quoted text 28 lines
Hi, I want to make a report of database data. The data has a master-detail relationship. For every master-record there are a fixed number of detail-records. A detail record = ItemCode, ItemValue So I make a lazreport. I put a masterheader band on the report and I put some text on it. Then I put a masterdata band on the report and I put some rectangle objects on that band and connect those the master-table. When I show the report, everything is like I want it. Next step is to add detail-fields. I though that using a cross-data band was the needed tool. On the crossing of the masterheader-band I put a rectangle-object and couple this to the detail-field ItemCode. On the crossing of the masterdata-band I put a rectangle-object coupled to the detail-field ItemValue. When I now show the report, my master-information is OK, for all master-records, but the detail-information is that of the first detail-record, for all master-records. Also the information of the detail in the master-header is OK. I have two grids showing the master-detail information so I know my queries are OK. What am I doing wrong ? Enclosed a screenshot. Green ovals contain correct data, the red oval contains bad data.

It would appear that your detail-field always points to the first item of your query. Which is not unexpected, because, most likely your detail fields come from a different query than that of the master fields. Master query automatically increment at each line, other data do not. If such is the case, you should take care of filling up your detail fields programmatically, using variables instead of query fields in your form, and taking advantage of a frWhateverGetValue, returning a ParValue taken from your query. Sort of:

procedure TMyForm.frWhateverGetValue(const ParName: String;
   var ParValue: Variant);
.....

if ParName = 'SA1' then ParValue := SQLQueryXX.FieldByName('SA1').AsInteger else if ParName = ...
....

and, for the last parameter of the line, incrementing to next line of your query. Sort of:

else if ParName = 'LASTParam' then begin
   ParValue := SQLQueryXX.FieldByName('LASTParamName').AsWhatever;
   SQLQueryXX.Next;
   end;

Of course this works fine if there's a one-to-one correspondence between master and detail query lines. Otherwise your code must be a little more elaborated.

Hope that it helps,

Giuliano

Reply by email

Koenraad Lelong
to Reinier Olislagers: (Note: haven't ever set up master/detail reporting in Lazreport, so just some ideas below)
Reinier Olislagers wrote 18 lines
(Note: haven't ever set up master/detail reporting in Lazreport, so just some ideas below) At least in other reporting solutions, master details means having some master band, then a detail band below it. This gives the following setup: Master1 record ...detail1:record1 ...detail1:record2 ... ...detail1.recordn Master2 record ...detail2:record1 ... ...detail2:recordn1 In other words, it supports single row reports only. No idea if this applies to lazreport.

This works fine in Lazreport, but it's not what I want. I want all data, including details, of the master-record on one line.

Show quoted text 12 lines
In other reporting solutions, if you want to have master+detail info next to each other, you can use a query in the database that provides the info in the desired layout. This is often known as s acrosstab query, searching gives e.g. Postgresql http://stackoverflow.com/questions/3002499/postgresql-crosstab-query Or http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=25 Obviously no idea if this applies to lazreport as well.

This should work in Lazreport, but that's just a case of a masterband.

The point is then : what's the cross-data band used for ? How does it work ?

Anyway, thanks for your input.
B.T.W. I'm using Firebird as a database.

Koenraad.

Reply by email