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

Using report templates

edited February 2004 in General
I need some basic help in figuring out what the former developer was doing
in this project. I had originally created about 5 different reports. He
then took them and stored the templates for them in a table and created a
generic data module. What I have is a table with report names and their
templates stored in a BLOB field (IB database). On the Data Module I have
individual ibQuery components along with their associated datasource and
pipeline objects. I also have the IB report table, its datasource and
pipeline and a TrsReportTemplateVolume component.

There is no report (TppReport) in the DM and I think his intention was to
create this on the fly and link it to the appropriate template.

My question is how do I open the report in the report designer to modify it
some more?

I have:
put a TppReport on the DM,
set its DataPipeline to the pipeline for the report I want to modify,
in the Template area I have
set that dataPipeline to the pipeline for the table which has the
templates
set the datasource to the report table ds
put the name (as listed in the report table for this report) in the Name
field
put the field name (NAME) in the NameField
put the template field name (TEMPLATE) in the TemplateField
set Format to ftBinary
set SaveTo to stDatabase

Now what do I do in order to see my report and work with it? I had done
this myself I would know what is happening, but I'm kind of starting at the
end and trying to work back to how he set this up. If you could even point
me to where I could read up on this, it would help.

Thanks so much,
Carolyn

Comments

  • edited February 2004
    Hi Carolyn,

    There are a few ways to edit your report if they are saved as blob data in a
    database. The first would be to edit them on the fly at runtime using the
    end-user solution (i.e.. Report Explorer, Report Designer). This may
    require you to create more tables. If you would like more information on
    using the end-user solution, please see the ReportBuilder Developer's guide
    and check out the end-user demos located in the \RBuilder\Demos\4. EndUser
    Databases\InterBase\... directory.

    Another way would be to drop a TppReport and TppDesigner on a form. Then
    you would need to set the Report.Template.DatabaseSettings properties. You
    can set these using the Object Inspector at design time. Once you have all
    this set up, you would need to call Report.Template.LoadFromDataBase to load
    the template, then at runtime you could show the designer and edit your
    reports.

    One final way would be to save the templates to file on your hard drive and
    load them manually using the designer at design time. All you would need to
    do is create a simple function that did everything for you. Something like
    the following...

    procedure TForm1.LoadBtnClick(Sender: TObject);
    begin
    Report.Template.DatabaseSettings.DataPipeline := DBPipeline;
    Report.Template.DatabaseSettings.Name := 'All Data';
    Report.Template.DatabaseSettings.NameField := 'Name';
    Report.Template.DatabaseSettings.TemplateField := 'Template';

    Report.Template.FileName := 'c:\myTemplate.rtm';

    Report.Template.LoadFromDatabase;

    Report.Template.SaveToFile;
    end;

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2004
    Thanks for your help, but I am still having trouble. See in-line.

  • edited February 2004
    Hi Carolyn,

    Were you able to actually save the templates to an .rtm file? Are you only
    receiving these errors when trying to open the templates from the Report
    Designer at designtime? I am a bit unclear when you are seeing these
    errors. The message TraCodeModule Not Found implies that the template was
    made with some RAP code included and you either do not have the RAP language
    installed in your Delphi IDE or you are not using ReportBuilder Enterprise
    Edition. You can check this by selecting the Component | Installed Packages
    option from the Delphi IDE. Be sure the ReportBuilder RAP Language is
    present and checked. If it is not, you can try to add it by clicking the
    Add button and browsing to the \RBuilder\Lib\dclRAP##.bpl. (the ## stand
    for the version of RB and Delphi you are using).

    --
    Best Regards,

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

    I was not able to get the templates to an .rtm file. I created a new
    application with a single form. On it I put the items I needed to connect
    to the Interbase database which has the Report table which has my templates
    in it (which another developer put together and loaded and now he is gone),
    and a TppReport object. I put a button on the form and it has the following
    code:

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Report.Template.DatabaseSettings.DataPipeline := ppdbpReport;
    Report.Template.DatabaseSettings.Name := 'Provider Billing Summary';
    Report.Template.DatabaseSettings.NameField := 'Name';
    Report.Template.DatabaseSettings.TemplateField := 'Template';

    Report.Template.FileName := 'c:\My-Reports\Reports\PvdBillSumm.rtm';

    Report.Template.LoadFromDatabase;

    Report.Template.SaveToFile;

    end;

    If I use the report name (which is what is in the template table as that
    name) listed above I get the TraCodeModule message, if I change it to the
    name of the report I know needs to be fixed, I get an invalid value message
    for one of my variables in the report. The message occurs as soon as I
    press the button.

    These reports were built using some RAP to calculate summary values and
    percentages.

    I have the RAP language installed (dclRAP77.bpl), and I believe we have the
    Enterprise edition (how do I check to be sure?)

    Thanks for your continued help,
    Carolyn

  • edited February 2004
    Hi Carolyn,

    Sorry, apparently it's been a little tough for me to wake up this morning
    :).

    After looking at what was going on, I realized two things that could be
    causing you problems.

    1. In order for your templates to load correctly in your new application,
    you need to be sure to link in all the files that the templates used in your
    end-user application. For instance, if some of your templates used RAP, you
    will need to include raCodMod in your "uses" clause. If you have some DADE
    datamodules, you will need to include daDataModule etc. I would take a look
    at the original "uses" clause and simply copy over the units you have not
    included to be sure.

    2. One thing I noticed about the code I sent you was that it does not
    assume that two report templates could have the same name, just be in
    different folders in the Report Explorer. I assume the person working on
    these reports before saved them to the database using the Report Explorer.
    Since the Report Explorer allows separate folders, all the records in the
    Name field are not necessarily unique. If you think this may be the case
    with your application, take a look at the following article to work around
    this.

    ---------------------------------------------------------------
    Tech Tip: How to Programmatically Load Reports that were Saved
    using the Report Explorer
    ---------------------------------------------------------------

    1. The ReportExplorer has a run-time interface you can use to load
    reports using the ReportExplorer.LoadReport method. You can use this
    method without actually 'showing' the report explorer form. (See the
    online help topic for TppReportExplorer.)

    2. If you want use Report.Template.LoadFromDatabase, RB will locate the
    report stored in the database table based upon the NameField value only.
    However, for the rb_item table you really need Folder_Id, Name to locate
    a record uniquely.

    To override this default behavior, you can assign an event-handler to
    the Report.Template.OnLocateRecord event.

    example:

    TmyForm = class(TForm)
    private
    function ReportLocateRecordEvent(Sender: TObject; const
    aReportName: String): Boolean;

    end;

    procedure TmyForm.FormCreate(Sender, TObject);
    begin
    {assign the event handler}
    FReport.Template.OnLocateRecord := ReportLocateRecordEvent;

    end;


    function TmyForm.ReportLocateRecordEvent(Sender: TObject; const
    aReportName: String): Boolean;
    begin
    {add logic here to locate the record and return True if it is found}

    Result := myLocateReportFunction(FFolderid, aReportname);

    end;

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2004
    Your first suggestion took care of the problem. I think I am back in
    business.

    Once I get this one fixed and move on to the other reports I need I will
    need to be storing these templates back into the report table. I am
    figuring that I will just do the reverse of what I did to get the template
    out, but what is the ReportExplorer and where do I go to read up on it?

    I worked with RB about 7 months ago and am just getting back into it now so
    I appreciate your patience as I relearn all this stuff.

    Thanks,
    Carolyn

  • edited February 2004
    Hi Carolyn,

    The Report Explorer gives you a Windows Exlporer type view of all the report
    templates on your database including the ability to edit, create, delete and
    save to file any of the reports. This is by far the easiest way to access
    reports saved in a blob field on a database however it must be done at
    runtime. If you would like to read more about the Report Explorer and how
    to use it, check out the ReportBuilder Developer's guide (page 217). Also,
    all the end-user demos use the Report Explorer. Check out the demo located
    in the \RBuilder\Demos\3. EndUser\1. Report Explorer\... directory.
    --
    Best Regards,

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