Home Subreports
New Blog Posts: Merging Reports - Part 1 and Part 2

Titleband issues in sub reports in dynamically created reports

edited June 2004 in Subreports
I can't seem to get anything to show in the title band of a sub report
when the report is created in code. I can create and see items in the
detail band just fine.

One thing that's a little confusing is that I don't seem to need to
"create" the detail band. It seems to be there by default. If I build a
TppSubReport using visual components I can see that a "detail" band is
there by default, as well as a "title" band, yet attempting to work with
the title band in a dynamic setting raises an exception where working
with the detail band does not.

Here's a code sample:

//MainReport is a TppReport.

With TppSubReport.Create(MainReport) do begin
Band := aReport.DetailBand;
CreateReport(MainReport);
With TppChildReport(Report) do begin
DataPipeline := SubDataPipeline;
PrintBehavior := pbSection;

TitleBand.Height := 3;
{Raises an access violation}


With TppLabel.Create(TitleBand) do begin
Left := 1;
Band := DetailBand;
Caption := 'Sub Stuff';
end;
{Does not raise any exception, but doesn't display anything on the
report, either.}

For i := 0 to SubDataSource.DataSet.FieldCount - 1 do begin
With TppdbText.Create(DetailBand) do begin
Left := i * 1;
Band := DetailBand;
DataPipeline := SubDataPipeline;
Datafield := SubDataSource.DataSet.Fields.Fields[i].FieldName;
end; //With TppdbText
end; //For
{The FOR Loop works like a champ.}
end; //With TppChildReport
end; //With TppSubReport

Comments

  • edited June 2004

    1. Check out the Code Based thread of the Tech Tips newsgroup for examples
    of creating repprts in code.

    2. You can call Report.CreateDefaultBands to create a default set of bands.
    For subreport of type pbChild, this will create a Title, Detail, and Summary
    band. For a main report or a subreport of type pbSection, this
    CreateDefaultBands will create Header, Detail, and Footer.

    3. You can also create bands in code:

    example:

    uses
    ppBands;

    var
    lTitleBand: TppTitleBand
    begin
    lTitleBand := TppTitleBand.Create(Self);
    lTitleBand.Report := myChildReport;


    end;


    --

    Nard Moseley
    Digital Metaphors Corporation
    www.digital-metaphors.com



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2004
    Thanks! Your advice worked. It probably should be noted that if anyone
    is going to add more than one subreport to be sure to remember to set
    the ShiftRelativeTo property to the previous subreport. Forgetting to do
    so causes sone very confusing results.

This discussion has been closed.