Skip to main content

How to Implement and Register Custom Print Preview Dialogs

  • 2 minutes to read

In addition to the three built-in Print Preview dialog styles available in the ExpressPrinting System, you can implement and use custom dialog styles. This topic describes how to implement a custom Print Preview dialog style and register it for future use.

In the ExpressPrinting System, you can select the Print Preview dialog style via the PreviewDialogStyle property of the currently active engine controller or dxPSEngine global object. Each style represents a form (DFM and PAS files) that is registered within the ExpressPrinting System via a specially designed Print Preview dialog manager. The following table lists all the built-in Print Preview dialog styles, their respective units, and classes.

Dialog Style Unit Form Class Name Description
Standard dxPSPrVwStd TdxfmStdPreview Uses standard TToolBar controls.
Advanced dxPSPrVwAdv TdxfmPreviewWdxBar Uses toolbars shipped with the ExpressBars Suite, which must be installed separately.
Ribbon, Ribbon2010, Ribbon2013, Ribbon2016, Ribbon2016Tablet, and Ribbon2019 dxPSPrVwRibbon TdxRibbonPrintPreviewForm Uses Ribbon controls shipped with the ExpressBars Suite, which must be installed separately.

To implement a custom dialog style, all you need to do is to derive your style’s form class from one of the built-in classes listed above.

type
  TMyStandardPreview = class(TdxfmStdPreview)
  // Add your custom members here
  // ...
  end;

After this, you must provide the registration information about the style by implementing a TdxPSPreviewDialogStyleInfo descendant, as shown below.

type
  { TMyStandardPreviewDialogStyleInfo }
  TMyStandardPreviewDialogStyleInfo = class(TdxPSPreviewDialogStyleInfo)
  public
    class function CreatePreviewWindow: TdxPSCustomPreviewWindow; override;
    class function GetName: string; override;
    class function GetUnitName: string; override;
  end;
...
implementation
...
{ TMyStandardPreviewDialogStyleInfo }
class function TMyStandardPreviewDialogStyleInfo.CreatePreviewWindow: TdxPSCustomPreviewWindow;
begin
  with TdxfmStdPreview.Create(nil) do
    Result := Preview; 
end;
class function TMyStandardPreviewDialogStyleInfo.GetName: string;
begin
  Result := 'MyStandard'; // the dialog style's name
end;
class function TMyStandardPreviewDialogStyleInfo.GetUnitName: string;
begin
  Result := 'MyStdPreview'; // the name of the dialog form's unit
end;

Now, you can register the style and revert its registration by passing the registration information to the Print Preview dialog manager’s RegisterPreviewDialog and UnregisterPreviewDialog methods within the initialization and finalization sections, as shown below:

initialization
  dxPSPreviewDialogManager.RegisterPreviewDialog(TMyStandardPreviewDialogStyleInfo);
//...
finalization
  dxPSPreviewDialogManager.UnregisterPreviewDialog(TMyStandardPreviewDialogStyleInfo);

To activate the dialog style, assign its name to the TdxPSEngineController.PreviewDialogStyle, TdxPSEngine.PreviewDialogStyle, or TdxPSPreviewDialogManager.CurrentPreviewDialogStyle property:

dxPSEngine.PreviewDialogStyle := 'MyStandard';