[Lazarus] Lazreport master-detail on one line
Giuliano Colla
giuliano.colla at fastwebnet.it
Mon May 26 19:39:37 CEST 2014
Il 26/05/2014 13:26, Koenraad Lelong ha scritto:
> 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
More information about the Lazarus
mailing list