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

Preview report in full screen (cont.)

edited May 2003 in End User
Dear All.

I would like to preview report with size of the preview form in full screen.

I'm currently using this coding.

with ppReport1 do begin
DeviceType := 'Screen';
Print;
end;

I came up with some coding at the OnPreviewFormCreate event, this works just
fine.

OnPreviewFormCreate...
with ppReport1.PreviewForm do begin
WindowState := wsMaximized;
TppViewer(Viewer).ZoomPercentage := 100;
end;

Unfortunately, I have to load report template (.rtm) on each prininting
because I only use one single TppReport on my form to preview and print
several reports, so I modified my coding to preview the report like this

with ppReport1 do begin
DeviceType := 'Screen';
Template.FileName := 'my_report_template.rtm';
Template.LoadFromFile;
Print;
end;

With these extra coding my OnPreviewFormCreate is never fired again, so I
just tried to get rid of "Template.LoadFromFile", thing is back to normal.
So I just confuse what's wrong with the LoadFromFile method, why when I call
to this method it just prevent OnPreviewFormCreate (and actually other
events) not to fire anymore. What's the alternative to do?

Thanks to all, and especially to Moisey.

I'm using ReportBuilder Ent 5.56

Kongthap Thammachat
jeud@yahoo.com
ICQ: 13026976

Comments

  • edited May 2003
    I don't know about "events don't fire after call to the LoadFromFile method"
    issue, but wouldn't it be much easier to just inlude whatever you do in your
    OnPreviewFormCreate event right before the call to the ppReport1.Print?
    In your case that whould look like this:

    //Your code
    with ppReport1 do begin
    DeviceType := 'Screen';
    Template.FileName := 'my_report_template.rtm';
    Template.LoadFromFile;
    //OnPreviewFormCreate - handler (before Print)
    WindowState := wsMaximized;
    TppViewer(Viewer).ZoomPercentage := 100;
    //Print itself
    Print;
    //Your code again
    end;



  • edited May 2003
    Hi Kongthap,


    --------------------------------------------
    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: Working with Report Templates
    ----------------------------------------------

    Whenever you save a template to an .rtm file, all of the published
    properties of the Report are saved. This includes all Properties
    and Events that are visible in the Object Inspector. For the events,
    the 'name' of the event-handler procedure is saved.

    When you load an .rtm all of the properties values of the TppReport
    component are set to the values that were stored to the .rtm.

    If you load an .rtm that had OnStartPage assigned then it will
    be re-attached - provided that the event-handler method is a published
    procedure of the report's owner. The Owner is normally the form.


    On the other hand, if you load an .rtm that did NOT have OnStartPage
    assigned
    when it was saved, you will need to programmatically assign the
    event-handler.

    Example:

    You have a form with an event-handler for OnStartPage...

    type
    Form1 = class(TForm)
    procedure Form1StartPageEvent(Sender: TObject);

    end;

    You need to attach the event-handler after loading......

    myReport.Template.LoadFromFile;
    myReport.OnStartPage := Form1StartPageEvent;

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



    HTH,
    Chris Ueberall;
This discussion has been closed.