AfterPreview OnClose - TppPreview
I'm using D7, RB12.05
My overall goal is loading and saving the preview forms size/position
and preview settings. I've tried using the TppReport's
OnPreviewFormCreate and OnAssignPreviewFormSettings along with
OnPreviewFormClose. However when I change the Report.PreviewForm's
left, top, width, height in the OnPreviewFormCreate event, my changes
are ignored.
So I thought I'd try creating a TMyPreview = class( TppPreview ) and
registering my preview class. This has worked fine by overriding the
BeforePreview event but now I'm looking for something similar for the
AfterPreview.
I was able to override PerformPreviewAction and in the case of paClose
do what I need. However the paClose action only happens if they click
the close button and not if they click X or alt-F4.
I'd like to tap into some event (OnClose, AfterPreview) when the Preview
form closes. I'm not sure where to go from here. Do I need to create my
own preview class from TppCustomPreview? But it looks like
TppPrintPreview is the one that calls BeforePreview, so I would instead
need to create my own TppPrintPreview class and figure out where to call
AfterPreview?
Any thoughts?
Also I'm just not understanding the relationship between
ppPreview.TppPreview and ppPrvDlg.TppPrintPreview, could someone give me
a brief explanation?
Daniel
My overall goal is loading and saving the preview forms size/position
and preview settings. I've tried using the TppReport's
OnPreviewFormCreate and OnAssignPreviewFormSettings along with
OnPreviewFormClose. However when I change the Report.PreviewForm's
left, top, width, height in the OnPreviewFormCreate event, my changes
are ignored.
So I thought I'd try creating a TMyPreview = class( TppPreview ) and
registering my preview class. This has worked fine by overriding the
BeforePreview event but now I'm looking for something similar for the
AfterPreview.
I was able to override PerformPreviewAction and in the case of paClose
do what I need. However the paClose action only happens if they click
the close button and not if they click X or alt-F4.
I'd like to tap into some event (OnClose, AfterPreview) when the Preview
form closes. I'm not sure where to go from here. Do I need to create my
own preview class from TppCustomPreview? But it looks like
TppPrintPreview is the one that calls BeforePreview, so I would instead
need to create my own TppPrintPreview class and figure out where to call
AfterPreview?
Any thoughts?
Also I'm just not understanding the relationship between
ppPreview.TppPreview and ppPrvDlg.TppPrintPreview, could someone give me
a brief explanation?
Daniel
This discussion has been closed.
Comments
TppPreview is what is known as a preview plugin (this one being the
default plugin). The reason we use a plugin architecture is so that we
can use the same previewer (code) when a user prints to screen
(Report.Print) and when tabbing to the preview tab in the report
designer. It also allows you to create a single preview plugin and have
your changes reflected in both places.
When you print to the screen a TppPreview object is created and sent a
TWinControl to act as its parent form. This is the TppPrintPreview
(When you hit the preview tab in the designer, the tab control is sent
to the TppPreview instead). The TppPrintPreview is simply an empty
TForm with a number of passthru properties to access the TppPreview
object from the report. Once the TppPrintPreview form is passed to the
TppPreview, the TppPreview then begins creating all the preview
components such as toolbars, viewer, outline, etc.
To access the TppPrintPreview object from the report, you simply access
the TppReport.PreviewForm property. From there you can implement any of
the form events you might need without having to create a custom plugin.
procedure TForm1.ppReport1PreviewFormCreate(Sender: TObject);
begin
ppReport1.PreviewForm.OnClose := ehPreviewForm_Close;
end;
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
custom TppPreview as I can then apply this to all of my reports rather
than changing each report.
I found that setting any of the TppPrintPreview's Width,Height,Left or
Top properties in the TppPreview.BeforePreview event were ignored,
basically to early (before the form showed).
So instead I'm simply going to tie into the OnShow and OnClose events of
the TppPrintPreview, and it's working great. Unless there is something
something disastrously flawed with this approach...
The whole reason I'm doing this is that we defaulted all of our reports
to PreviewFormSettings of wsMaximized and zsPageWidth. Works great
unless you RDP to a terminal server and use /SPAN with more than one
monitor. So I'm implementing a custom sizing solution for this
situation (per user per report).
TMyPreview = class( TppPreview )
private
FHoldPrintPreviewOnClose: TCloseEvent;
FHoldPrintPreviewOnShow: TNotifyEvent;
procedure MyPrintPreviewOnClose(Sender: TObject; var Action:
TCloseAction);
procedure MyPrintPreviewOnShow(Sender: TObject);
public
constructor Create(aOwner: TComponent); override;
end;
constructor TMyPreview.Create(aOwner: TComponent);
begin
inherited;
if (Parent is TppPrintPreview) then
begin
FHoldPrintPreviewOnClose := TppPrintPreview(Parent).OnClose;
TppPrintPreview(Parent).OnClose := MyPrintPreviewOnClose;
FHoldPrintPreviewOnShow := TppPrintPreview(Parent).OnShow;
TppPrintPreview(Parent).OnShow := MyPrintPreviewOnShow;
end;
end;
procedure TMyPreview.MyPrintPreviewOnClose(Sender: TObject; var Action:
TCloseAction);
begin
if (Sender is TppPrintPreview) then
begin
...my code before the form is closed...
if Assigned(FHoldPrintPreviewOnClose) then
FHoldPrintPreviewOnClose( Sender, Action );
end;
end;
procedure TMyPreview.MyPrintPreviewOnShow(Sender: TObject);
begin
if (Sender is TppPrintPreview) then
begin
if Assigned(FHoldPrintPreviewOnShow) then
FHoldPrintPreviewOnShow(Sender);
...my code after the form is shown...
end;
end;