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

integrating user reports with existing app

edited February 2007 in End User
I have a Delphi app that is quite complicated but ends up creating a record
used to generate a print of labels. Currently the app has a very old label
creation program that I would like to replace with RP end-user reporting.
If I knew each report layout now I would define them and build them into the
app as I do with most reporting requirments, but this is a company who
constatly need to modify labels for their customers needs.
I can see how the end user would design a new variation on the label using
the report designer tool, but how can this report be accessed by the
application?
I am sure there is a simple tutorial somewhere, can you point me to it?

kind regards

John Evans

Comments

  • edited February 2007

    - one option is to the RB ReportExplorer to store the report definitions in
    a database (rbFolder and rbItems tables). This approach is shown in the
    examples and tutorials installed with the product. Check out
    RBuilder\Demos\EndUser\ReportExplorer for an example. The advantage of this
    approach is that there is one central repository for storing the report
    definitions. To programmatically load the report definitions stored in the
    rbItems table, see the tech tip below (the tech tip is also available on
    Templates thread of the tech tips newsgroup).

    - the other option is to /not/ use the ReportExplorer. The ReportDesigner
    can be used to save/load reports to .rtm files (just was you do with
    applications such as MS Word).



    ---------------------------------------------------------------
    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;








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


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited February 2007
    Dear Nard,
    thanks for the below.

    I am going the route of storing the reports in the database and then using
    loadfromDB to get them again.

    I have created a function as you suggested to find the report in rbItem

    function TfrmCust.ReportLocateRecordEvent(Sender: TObject; const
    aReportName:String): Boolean;
    begin
    result:=false;
    datamod.qrbitem.Open;
    {add logic here to locate the record and return True if it is found}
    if datamod.qrbitem.Locate('folderid;itemname', vararrayof([1, 'bar
    code']),[])
    then
    begin
    showmessage('found it');
    Result :=true;
    end;
    end;

    I have a empty report component on a form, ppreport2

    I also added the event to the form.Create

    ppReport2.Template.OnLocateRecord := ReportLocateRecordEvent;


    I press a button and execute

    if ReportLocateRecordEvent(sender,'bar code') then
    ppreport2.Template.LoadFromDatabase;


    The showmessage appears, so I have found the record OK, however the
    loadfromdatabase returns the error
    Etemplateloaderror 'Record not found: '

    Which bit am I missing/mis-understanding.

    kind regards

    John









  • edited February 2007

    I think you misunderstand.

    - At Delphi design-time configure the Report.Template.DatabaseSettings to
    bind to the rbItem DataSet via a DBPipeline. You do this by specifying the
    Report.TemplateDataSettings properties for DataPipeline, NameField and
    TemplateField properties.

    - At run-time assign the event-handler in the Form Create (as you showed in
    your sample)

    myReport.Template.OnLocateRecord := ReportLocateRecordEvent;

    - At run-time specify the Name of the report that you want to load

    myReport.Template.DatabaseSettings.Name := 'bar code'; // or whatever the
    name

    - and finally load the report

    myReport.Template.LoadFromDatabase

    - Now, the event-handler will fire. (In your example you called the
    event-handler).



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

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited February 2007
    Dear Nard,
    SUCCESS!!

    many thanks

    John


This discussion has been closed.