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

Reporting questions

edited June 2004 in General
Hi,

I have a report form that contains a couple pipelines, datasets, tables and
a report and designer. At run time I set the tablenames and databases as
well as load a template into the report. When doing this, there are cases
when I do not wish to print certain detail bands ( if amount and count are
zero ) Is there a good way to prevent these from printing?

Jonas

Comments

  • edited June 2004
    Hi Jonas,

    The easiest way to do this would be to use RAP. RAP allows you to write
    event code that is saved local to the template. Then inside the
    DetailBand.BeforePrint event you could toggle the visibility of the detail
    band based on some criteria. If you do not have RAP, you will need to write
    the event code in Delphi and then assign the event handler to the report
    after the template has been loaded in the template event OnLoadEnd. Please
    see the Tech Tips newsgroup in the Templates | Using Template Events...
    article for more information on enabling these events.

    --
    Best Regards,

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

    We do not have RAP. I could not locate the Templates|Using template Events
    in the tech tips.
    So will I be able to load different report templates into my main
    reportform, or do I need separate forms for each report in order to use
    these even handlers properly? I am new to this report builder, and would
    greatly appreciate the help.

    Thanks,

    Jonas
  • edited June 2004
    Hi Jonas,

    Without the use of RAP, keeping the event handlers referenced to multiple
    templates will be very difficult. I posted a couple articles below that may
    be of some use to you. The easiest way around this problem without using
    RAP is to have a separate TppReport object for each template, which kind of
    defeates the purpose of templates, but will be guarenteed to work correctly.

    --------------------------------------------
    Article: Troubleshooting Lost Event Handlers
    --------------------------------------------

    Let's assume you have created a report in Delphi and assign an event
    handlers to the OnPreviewFormCreate event of the report. The event is
    generated by Delphi as:

    procedure TForm1.ppReport1PreviewFormCreate(Sender: TObject);

    You then save the report to an RTM file 'Report1.RTM.' The events are
    stored as references only, and so the RTM contains:

    object ppReport1: TppReport
    .
    .
    OnPreviewFormCreate = ppReport1PreviewFormCreate
    end

    You then go on to work on a different report. Saving it with under then
    name 'Report2.RTM'. Only this time, before you save the report you
    change the report component name to: rptOrders. Delphi automatically
    updates the event declaration for OnPreviewFormCreate event to:

    procedure TForm1.rptOrdersPreviewFormCreate(Sender: TObject);


    You then create two buttons on the form, one to load Report1 and
    preview, the other to load Report2 and preview. When you run the app
    and click Report1, you an error. This is because the Report1.RTM file
    contains a reference to ppReport1PreviewFormCreate, a method which no
    longer exists (at least with this name) in the form.

    One answer is to load all your rtm files into the report component you
    will be using for loading. Fix any errors, reassign any events that get
    cleared. This will update your rtms to contain the proper event handler
    names.


    ----------------------------------------------
    Tech Tip: Using Template Events
    ----------------------------------------------

    The Report.Template object has several events that can be used for
    customizing what happens when a report is loaded or saved:

    - OnLoadStart
    - OnLoadEnd
    - OnNew
    - OnSaveStart
    - OnSaveEnd


    The OnLoadEnd and OnNew events are often used to perform actions related
    to report and data initialization.

    The OnSaveEnd event is often used to save additional descriptive
    ("meta") data to the database each time the report is saved.

    Example:

    The Report.Template events are public and therefore must be assigned at
    run-time.


    1. In the private section of your form declaration you can declare an
    event-handler method:

    TForm = class(TForm)
    private
    procedure myTemplateOnLoadEndEvent(Sender: TObject);

    public

    end;


    2. In the Form.OnCreate event, you can assign the event-handler to the
    event:

    procedure TForm1.FormCreate(Sender: TObject);
    begin

    ppReport1.Template.OnLoadEnd := myTemplateOnLoadEndEvent;

    end;


    3. Implement the event-handler method:

    procedure TForm1.myTemplateOnLoadEndEvent(Sender: TObject);
    begin

    {add code here to initial the report or data, etc. }
    ppReport1.PrinterSetup.MarginTop := 0.5;

    end;


    --
    Best Regards,

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

    Thank you again for your reply. Yes, it seems as RAP would be the definate
    way to go if performing specific operations within the report. However, for
    now I think I will just go ahead and filter the data instead. Eventually, an
    upgrade is likely though.

    Thank you for your help!

    Jonas

This discussion has been closed.