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?
If you are using the latest version of ReportBuilder you can use the Viewer.ScrollablePaintBox.VerticalScrollbar.Pos property to determine the current vertical position.
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"?
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
//Once the viewer is ready, navigate to the saved vertical position if not(lViewer.Busy) then lViewer.ScrollablePaintBox.VerticalScrollbar.Position := FYPos;
Comments
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.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
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
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;
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com