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

A Question About Dynamic Loading SubReports

edited June 2004 in Subreports
The demo for this uses the LoadFromFile or LoadFromDatabase,
I chose to do this a little differently for one subreport that I do not
want the user to be able to delete or alter.

the code basically looks like this:

FReport := TppChildReport.Create(Self);
with FReport do begin
...
end;
FDetailBand := FReport.AddBand(btDetail, 0);
with FDetialBand do begin
...
end;
FLabel1 := TppLabel.Create(FDetailBand)
with FLabel do begin
...
Band := FDetailBand;
OnGetText := Label1GetText;
end;

There are more components but that's enough to see what is
going on. Next I load this into the tempplate.

aStream := TMemoryStream.Create;
FReport.Template.SaveToStream(aStream);
Report.Template.LoadFromStream(aStream);
aStream.Free;

All of this works just fine, no problems no errors.
Except for the OnGetText event, it does not fire.

My question -- is there some way to get the events to fire,
or do they not fire by design.

Thanks to anyone who can help.

Comments

  • edited June 2004

    Check out the Code Based thread of the TechTips newsgroup. There you can
    find articles with sample code. You are not creating the reports in quite
    the correct manner. The Owner of all report elements should be the
    form/datamodule. Never call AddBand, instead set the Band property of the
    component (i.e. myLabel.Band := myReport.Detail).

    As for the event-handler not firing my guess is that when the report
    definition is loaded from stream, the event-handler assignment is lost. The
    event-handler method needs to be a published method of the form/datamodule
    that Owns the report.


    --

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



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2004
    You were right about the events, all I needed to do is cycle through
    the band.objects and assign the events to the appropriate object after
    the report definition is loaded from stream.

    Thanks for the additional info on the Bands, that might be
    why if I have the SubReport active in the Design tab go to
    the Preview tab and then back to the Design tab with the
    SubReport still active, I get an endless access violation.

  • edited June 2004
    I changed the band assignments, and all works fine.

    I still have one problem, here is what I do to produce
    the problem. I also tried this with the Dynamic Loading
    SubReports demo and the problem occurs there as well.

    1. Set report bands: Title, Detail, Summary.
    2. Add Dynamic Subreport to title band.
    3. Click Preview tab
    4. Click Design tab
    5. Make Dynamic SubReport the active page in the Design tab
    6. Click Preview tab
    7. Click Design tab

    Result is an endless access violation.

  • edited June 2004


    This example shows another approach, which is to use reference style
    subreports. It is much simpler.

    www.digital-metaphors.com/tips/SubReference.zip

    --

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



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2004
    This example is nice, and yes it is much simpler, but what
    about the problem with the Dynamic Loading SubReports
    causing an access violation.

    I don't think I mentioned it but I'm using
    Delphi 5
    Report Builder Professional 7.01

  • edited June 2004

    I can recreate that issue here. Therefore you have discovered that the
    example has problems. Sorry about that. I traced the RB source code and even
    attempted a couple of mods, but have not found any solution yet....


    --

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



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2004
    I'm only using the Header band in my DLS, if my DLS is set to
    another band it is basically just a standard SubReport.

    Here is a solution that works for me.

    TmySubReport = Class(TppSubReport)
    private
    FSubReportLoaded: Boolean;
    procedure LoadTitleSubreport;
    public
    constructor Create(aOwner: TComponent); override;
    destructor Destroy; override;
    procedure StartOfMainReport; override;
    published
    property SubReportLoaded: Boolean read FSubReportLoaded write
    FSubReportLoaded default false;
    end;

    procedure TmySubReport.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);

    FSubReportLoaded := False;
    end;

    destructor TmySubReport.Destroy;
    begin
    inherited Destroy;
    end;

    procedure TmyDynamicLoadingSubReport.StartOfMainReport;
    begin
    inherited StartOfMainReport;

    if (Band is TppHeaderBand) and Not FSubReportLoaded then
    LoadTitleSubreport;
    end;

    procedure TmySubReport.LoadTitleSubReport;
    begin
    if FSubReportLoaded then Exit;

    // Lines of code to add components

    FSubReportLoaded := True;
    end;

    initialization
    ppRegisterComponent(TmySubReport, 'Demo Components', 0, 0, 'Dynamic
    Loading SubReport', 0);

    finalization
    ppUnRegisterComponent(TmySubReport);

    end.

  • edited June 2004

    Thanks for providing that solution. I tried adding similar code to the
    example and it resolved the issue there as well. :)


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



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.