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

Storing a report as a string

edited July 2003 in General
Howzit,
Using RB v6.03.

I am using a TppViewer component to preview reports. Once the report is in
preview, I want to be able to stream it to a string. This i am doing now by
first getting the TppReport to save to file, then streaming the file back
into memory. How do i get a string that represents the previewed report
without first streaming the report to file.

Secondly,
When i want to stream the string back to the viewer, if have to do simillar:
Stream the string to file, use a TppArchiveReader to read the file back to
the TppViewer. This not only has the step of saving to file, but when i call
the TppArchiveReader.Print method, a preview dialog pops up (when i just
want the report to show in the TppViewer).

Regards,
Gilbert

Comments

  • edited July 2003
    Gilbert,

    - What is your ultimate goal in saving a report to a String? If you are
    trying to take a snapshot of a report, you may just want to stick with using
    archive files and sending them to the viewer. If not, I attached an example
    that may help. It shows how to send a report page to a memory stream and
    then directly to a TppViewer. Similarly, you could send the memory stream
    to a String component.

    - When streaming back to the viewer, you need to set the Publisher of the
    Screen Device equal to the Publisher of the Archive Reader and then call
    PrintToDevices. Something like the following.

    Viewer.ScreenDevice.Publisher := ArchiveReader.Publisher;
    PrintToDevices;

    There is a demo available with ReportBuilder 7.02 that demonstrates this
    (demo 155). You can see this demo by downloading a trial copy of RB 7.02.

    http://www.digital-metaphors.com/tips/PageAsStream.zip

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited July 2003
    Nico,
    My ultimate goal is to take a snapshot of the report, put it into a XML
    document and send it to our server for database storage - so a file is not
    an ideal solution. Thanks for the code example, is there no way of doing
    this for the entire report rather than page by page?
    Regards,
    Gilbert

  • edited July 2003
    Gilbert,

    If you just need to store a snapshot of a report on your server, why do you
    need to put it into an XML document? It would be much easier to use the
    Archive Device and then stream the Report Archives to a Blob field on your
    database. Then the work is almost already done for you. All you would have
    to do is post the report archives to your database server. Below is a link
    to Demo 155. This will give you a better idea of what I am talking about.

    http://www.digital-metaphors.com/tips/Dm0155.zip

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited July 2003
    Nico,
    Our server is a DLL that is communicates with our client through XML
    documents over HTTP. Unfortunately, although this gives us huge benefits -
    it does not allow us to liberally use datasets. So i would still have to
    stream the blob field to a string even if i got the archiver to save to a
    TDataset component. So the bottom line seems that either i stick with the
    current way (using a file) or try to save to Blob, then stream blob to
    TStringStream in order to populate my XML.
    Thanks,
    Gilbert Grant
    Cura Risk Management Software

  • edited July 2003
    Hi Gilbert,

    I see... take a look the the TppCustomFileDevice class located in the
    ppFilDev.pas file. You may want to create a custom device that instead of
    writing to a file, writes to a memory or String stream as you described
    below. Once you register a new device, you can set it as the default print
    device and stream all your reports automatically.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited July 2003
    Nico,
    Unfortunately (for this case), our client and server communicate through
    HTTP and we do not have liberal use of datasets. So transferral to XML
    document is mandatory. Unless it is possible to create a TDataset with a
    TBlobField, save the archive to this TBlobField, then stream the Blob to
    String - also almost as indirect as using a file, but negating my main issue
    that i have trouble reliably cleaning up the files (i.e. removing them from
    disk) as I am not sure then the Archiver releases the handle to the file. I
    cannot use the TDataset to save directly to the DB. Anyway, will try to find
    a way.
    Thanks,
    Gilbert

  • edited July 2003
    Gilbert,

    Sorry about the delay in this response. I believe your best approach would
    be to create an XML device to handle your needs. You would need to create a
    descendent of the TppFileDevice class similar to the TextFile Device or the
    Archive File Device. See these devices for ideas on how to create your own.

    --
    Best Regards,

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