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

Programatically Loading a Report Template in a Thread

edited January 2007 in End User
Hi There

Company I work for has 3 offices (1 central, 2 remote).

We all have the same application in each office, but its centrally
configured. We have recently undertaken a project to provide an automatic
synchronisation of reports from central server to the remote servers. This
enables us to change the reports centrally and have them distributed
automatically. The Database/Application is identical on all 3 sites.

The issue I am finding is I cant seem to find a way to load just the
Template from a Thread.

In essence what I am trying to do from within a thread is as follows

Template : TppReportTemplate;
TemplateStream : TStringStream

Template := TppReportTemplate.Create(Nil)
....
<<Setup Table, DataSource, DBPipeLine>>
....

Template.DatabaseSettings.Name := ReportName;
Template.ShowBusyCursor := False;
Template.LoadFromDatabase;
Template.Format := ftASCII;
Template.SaveTo := stFile;
Template.SaveToStream(TemplateStream);

....
Send the string down the wire to the remote site with additional information
(Folder name etc).
....

The i've found is that by passing the owner of the Template as Nil, when
LoadFromDatabase is called, it's expecting the AOwner from the constructor
to be a Report (sets a Component State)

So instead - i switched over to using the End User Report Explorer (memory
bloat) in a thread. If I try and call rbExplorer.LoadReport (again from
within a thread), I end up with a System I/O Error 5 in TWinControl.Destory.
Tracing it back it was caused by a gui component in a thread. So on
rbExplorer, I set the designer property to Nil. Called LoadReport again. But
because there is no Designer set, the call to Initialise() within LoadReport
Fails because there is no designer. So Catch 22 - No Designer No Template
Load.

So how can I Load a Template of a Report from Within a Thread?

Any help/suggestions would be great.

Thanks
Scott

Comments

  • edited January 2007
    I am also interested in learning how to update reports saved in the DB from
    one DB to another. What would be the best way to do this?

    Would there be any way to save .RTM files of the report from code and then a
    way to load RTM files into the DB from code?

    OR

    Maybe you could send all the standard info from the DB field and then, since
    the template field is a BLOB, maybe you could do a Field.SaveToFile and save
    it as a text file, or some other extension (i don't think it really
    matters), and then on the remote end do a Field.LoadFromFile?

    I'm not sure if either of these would work or which would be the easiest or
    most efficient???


  • edited January 2007

    - TppReport.Template can be used to save/load a report layout from a stream,
    database, or .rtm file.

    - TppReport.Template.Format determines whether report layouts are saved as
    binary or ascii

    - The primary reason to use Report.Template for loading a report layout is
    to instantiate the Report.Bands[].Objects[] composite for the purpose of
    generating a report.

    - if the goal is to load/save/migrate the report layouts, then consider an
    approach that does /not/ use the Report.Template, but instead uses standard
    VCL classes for handling stream, database, or file data.

    This example might provide some ideas...

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


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

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited January 2007
    Hi Nard

    Just wanted to pass on a sincere thanks for the advice, especially the
    EditTemplateAsText.

    This was exactly what was required, and after some adaptation for TADOQuery,
    everything is synchronising now 100%.

    You're a Champion!

    Scott

This discussion has been closed.