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

List Index out of bounds (-1) with loading template

edited February 2004 in General
I thought it may be OK for me to add the attachment to this letter being
only 3k. Please let me know otherwise for future reference.

My problem is this:

I have some code (included in the example attached), which allows me to set
a template report that will be automatically loaded to all the reports I
develop within an application, to give them the same header. This works
fine. (Which you can see by pressing the BitBt1 button).

However, if I click on the UserDesign button to allow the user to edit one
of my reports, close the edit dialog, and try and print the report again by
pressing BitBtn1, I receive the error "List Index out of bounds (-1)". This
error occurs even if the user doesn't make a change to the report (ie, they
only open and close the editor).

Can someone please tell me how to fix this, or if I'm going about this the
wrong way?

Thanks & Regards

Adam Hair
Wimmera Software Development
Horsham, Victoria, Australia

Comments

  • edited February 2004
    Hi Adam,

    For future reference, please send all attachments to
    support@digital-metaphors.com.

    After tracing through your code, it looks as though in the special case
    where a TppDesigner is used in addition to the creation of dynamic
    subreports, you will need to set the subreport's band property before making
    the call to CreateReport. This is due to the fact that when a Designer has
    been defined, ReportBuilder tries to update it as well as the preview window
    when CreateReport is called. I will go ahead and update the tech tip to
    reflect this change. Thanks for pointing this out.

    Your Printit procedure should now look something like this...

    procedure TForm1.Printit(Report: TppReport; Caption : String);
    var
    tsub : TppSubReport;
    tchd : TppChildReport;
    ts1 : TStream;
    begin

    ppTemplateLabel.caption := caption;

    tsub := TppSubReport.Create(Report);
    tsub.Band := Report.HeaderBand;
    tsub.CreateReport(Report);

    tchd := tsub.report as TppChildReport;
    tchd.CreateDefaultBands;

    ts1 := TMemoryStream.Create;
    ppTemplate.Template.SaveToStream(ts1);
    tsub.Report.Template.LoadFromStream(ts1);

    Report.Print;
    tchd.free;
    tsub.free;
    ts1.free;

    end;

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2004
    Hi Nico,

    making

    Thanks very much for your reply. It works a treat! Would it be a problem to
    always set the subreports band property before making the call to
    CreateReport, regardless of which situation you use it in?

    Best Regards

    Adam.
  • edited February 2004
    Hi Adam,

    Yes. Believe it or not, that was the first time this issue has come up. I
    believe that we will start always recommending that our users set the
    subreport band property before calling CreateReport.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.