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

Saving form positions for built-in preview

edited April 2012 in General
I am using the built-in preview dialog when previewing my reports. Is there
any way to save the form positions from within my program so that I can
restore them when the preview dialog shows up again?

Thanks

Andy

Comments

  • edited April 2012
    Hi Andy,

    Which version of ReportBuilder are you using?

    If you are using the latest version of ReportBuilder you can use the
    Viewer.ScrollablePaintBox.VerticalScrollbar.Pos property to determine
    the current vertical position.

    Best Regards,

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

    Yes, I am using the latest version. Currently, I just call the
    "Report.Print" in my application. How do I access the "Viewer" and do I call
    this before running the "Report.Print"?

    Thanks and sorry for the ignorance.

    Andy

  • edited May 2012
    Hi Andy,

    You can access the viewer object after the preview form has been created
    by typecasting the Report.PreviewForm.Viewer property.

    You are going to want to use the Viewer.OnScroll event to keep track of
    the vertical scroll position, and the Viewer.PrintStateChange event to
    assign the initial position once the viewer is no longer busy. Below is
    the code I used in a simple example. I will create a RBWiki article
    soon with more detail.

    uses
    ppViewr;

    procedure TForm1.ppReport1PreviewFormCreate(Sender: TObject);
    var
    lViewer: TppViewer;
    begin

    lViewer := TppViewer(ppReport1.PreviewForm.Viewer);

    //Assign viewer events
    lViewer.OnPrintStateChange := eh_ViewerPrintStateChange;
    lViewer.OnScroll := eh_ViewerOnScroll;

    end;

    procedure TForm1.eh_ViewerOnScroll(Sender: TObject; aX, aY: Integer);
    begin
    //Keep track of the vertical position
    FYPos := aY;

    end;

    procedure TForm1.eh_ViewerPrintStateChange(Sender: TObject);
    var
    lViewer: TppViewer;
    begin

    lViewer := TppViewer(ppReport1.PreviewForm.Viewer);

    //Once the viewer is ready, navigate to the saved vertical position
    if not(lViewer.Busy) then
    lViewer.ScrollablePaintBox.VerticalScrollbar.Position := FYPos;

    end;

    Best Regards,

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