How To…Preview in a Panel

Question

“How can display the Preview as part of a form?”

Solution

This example shows how to create an instance of the Preview plug-in and display it on a panel. The Preview is a non-visual class that managers the viewer, toolbar, outline and other UI controls. It requires a parent, which can be a form or a panel.

Download: PreviewInPanel.zip

Sample Delphi code:

uses
  ppPreview;

procedure TForm1.FormCreate(Sender: TObject);
begin

  FPreview := TppPreviewPlugIn.CreatePreviewPlugin(Panel1);
  FPreview.Viewer.Report := ppReport1;
  FPreview.OnClose := ehPreview_CloseEvent;

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin

  FPreview.Free;
  FPreview := nil;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin

   if FPreview.Viewer.Busy then Exit;

    FPreview.BeforePreview;

    if ppReport1.InitializeParameters then

      // optionally display the autosearch dialog
      if ppReport1.DisplayAutoSearchDialog then
        begin
          FPreview.Viewer.Reset;
          ppReport1.PrintToDevices;
        end;

end;

procedure TForm1.ehPreview_CloseEvent(Sender: TObject);
begin

  Close;

end;