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

Report Page Caching Problem

edited June 2002 in General
Hi,

I am trying to cache pages from different reports so I can create a single
PDF. I create each report dynamically
setting CachePages := True and printing the report to a generic device. I
then call TppReport.Publisher.GetPageFromCache(X) and add the pages to my
TStringList using the AddObject.

Now when I actually free the report, it seems that the TppPages in the
TStringList also seem to get freed as well.

Can anyone confirm this and is there away around this so I can keep the
pages until I free the TStringList.

Thanks,
David.

Comments

  • edited June 2002
    ------------------------------------------------------------
    Tech Tip: Saving Page Objects After Freeing Report
    -----------------------------------------------------------

    When the report is freed it will free the publisher which will free the
    cached pages. To keep the pages around you cannot simply keep a reference to
    the pages because they will be invalid after the report is freed. You must
    copy each page and keep a reference to it instead as shown below. Afterwords
    you can free the report while retaining valid copies of the cached pages.

    procedure AddCachedPagesToList(aList: TList);
    var
    lDevice: TppDevice;
    lPage: TppPage;
    liIndex: Integer;
    begin

    lDevice := TppDevice.Create(nil);
    lDevice.PageSetting := psAll;
    lDevice.Publisher := ppReport1.Publisher;

    ppReport1.CachePages := True;
    ppReport1.PrintToDevices;

    for liIndex := 0 to ppReport1.Publisher.PageCount - 1 do
    begin
    lPage := TppPage.Create(nil);
    lPage.Assign(ppReport1.Publisher.GetPageFromCache(liIndex));
    aList.Add(lPage);
    end;

    lDevice.Free;

    end;

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

This discussion has been closed.