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

No Data Behaviour

edited March 2007 in End User
Hello all

How do I change the default NoDataBehaviour from a Blank Page to a Dialog. I
have tried setting the ndMessageDialog property to TRUE but I still get the
default behaviour.

Do i need to write any code to handle this?

This is for an end user solution

Cheers

mark

Comments

  • edited March 2007
    Hi Mark,

    If you are loading templates, this property will need to either be set in
    each individual template and resaved or set in code using the OnLoadEnd
    template event. Take a look at the following article on using template
    events.

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


    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2007
    Nico

    When you say in templates are you referring to reports saved in my back end
    database?
    To prove that theory if I create a new report and save that with the correct
    properties set would that NEW report behave with the No Data dialog box?

    What settings should I have on my report object to get the dialog box to
    display?

    Cheers

    mark


  • edited March 2007
    Nico

    I have used the OnLoadEnd to get the dialog to appear my code snippet is
    below

    rptPyramid.NoDataBehaviors := [ndMessageDialog];

    When this runs with no data I now get the dialog box which is great but I
    still get the blank page. Is there a way of not showing the end user the
    blank bage and JUST have the dialog box?

    Thanks

    Mark



  • edited March 2007
    Hi Mark,

    Inside the Report.OnNoData event, try closing the preview form.

    procedure TForm1.ppReport1NoData(Sender, aDialog: TObject;
    var aShowDialog: Boolean; aDrawCommand: TObject;
    var aAddDrawCommand: Boolean);
    begin

    ppReport1.PreviewForm.Close;

    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2007
    Nico

    I have this code

    procedure TfrmEndUserReport.rptPyramidNoData(Sender, aDialog: TObject;
    var aShowDialog: Boolean; aDrawCommand: TObject;
    var aAddDrawCommand: Boolean);
    begin
    showmessage('Here');
    rptPyramid.PreviewForm.Close;
    end;


    but it never fires, I get the Dialog box for No data, then the blank form
    but nothing else

    any ideas?

    Cheers

    Mark


  • edited March 2007
    --------------------------------------------
    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.


    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

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