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

empty report into the Database

edited March 2007 in General
Hello.

Maybe the question had been asked, but I want to know if there is a way
to insert manually into the database a empty report.

If I just make a record with NULL in the Template field, RB says invalid
template. Is there any means to do that ?

Thanks.

JFPicard

Comments

  • edited March 2007
    Also, if I may ask, I'm using the report designer without the report
    explorer and the Size, ItemType and Modified field of my report item
    table is always NULL. Do I have to put a report explorer into my form
    even without using it ?

    Thanks.

    JFPicard
  • edited March 2007
    You can use the report designer to create an empty report and then save the
    empty report to the database. (An "empty report" will be a report with at
    least a detail band. It will contain all of the published properties of a
    TppReport object)



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

    Best regards,

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

    Are you using the report explorer elsewhere in the application? Below are
    two tech tips. The first discusses using the report explorer database tables
    (rbFolder, rbItems). The second discusses defining a simple database that
    contains the name and template fields only.


    ---------------------------------------------------------------
    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 need Folder_Id, Name to locate a record
    uniquely.

    To override this default behavior, 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;



    ------------------------------------------------------
    Tech Tip: Loading Report Templates from a Database.
    ---------------------------------------------------

    Reports can be saved to a database at design-time or run-time.


    1. First, you need to setup a database table with a BLOB field for storing
    the templates and a string field for storing the name of the templates:

    For this example let's create a paradox table called reports.db


    Reports.db
    --------------------------------
    Reports Name char(40)
    Template blob


    Of course you can add other fields also, but this is what ReportBuilder
    needs.


    2. Connect the ppReport1.Template property to the database by setting the
    required properties. (you can do this with code or at design-time via the
    ObjectInspector.)

    {specify that the templates will be loaded and saved from a database}
    {the other valid value is stFile}

    ppReport1.Template.SaveTo := stDatabase;


    {note: stDatabase is defined in ppTypes, therefore you will need to add
    ppTypes to the 'uses' clause of your unit.}

    {note: you'll need a DataSource and a DataPipeline to connect the reports.db
    to the template, so let's say we've done that and have a DataPipeline called
    dpReports}

    {specify the datapipeline and datafield names to connect everything}

    ppReport1.Template.DatabaseSettings.DataPipeline := dpReports;

    ppReport1.Template.DatabaseSettings.NameField := 'Name';
    ppReport1.Template.DatabaseSettings.TemplateField := 'Template';


    3. Specify the name of the particular template you want to load or save.
    (again you can do this at run-time or via the object inspector.)

    ppReport1.Template.DatabaseSettings.Name := 'myTestReport'


    4. Save or Load the report template.

    (You can also do this at design-time using the menu options File | Open &
    File | Save. The reportdesigner will attempt to load from a file when you
    specify ppReport1.Template.SaveTo := stFile and will attempt to load from
    adatabase when you specify stDatabase. If you specify stDatabase and do not
    specify the other DatabaseSettings props mentioned above, the options may be
    disabled.)

    ppReport1.Template.SaveToDatabase;
    ppReport1.Template.LoadFromDatabase;

    That should about cover it. I would try setting all the properties at
    design-time and getting that working first.

    Then you can try the run-time stuff.


    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com



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


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.