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

Prevent Print Dialog From Showing

edited December 2014 in General
I'm trying to prevent the PrintDialog window from displaying after the printer icon from the print preview toolbar is clicked. How can I do this?

I'm trying to accomplish the following in the trial version of my software:

1. On button click open the report in the print preview.
2. On click of preview toolbar printer icon display printing disabled message.
3. Prevent the print dialog box from showing.

I want potential users to see all the functionality that exists including the print preview functionality. However, if they click the preview toolbar printer icon I'd like to display a printing disabled message and then have the process end there.

The work around I have in place is to iterate through all the controls on the printdialog form and set enable := false for all TButton controls.

I was hoping for a better solution.

Thanks in advance.


//===========================================================
unit Unit5;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils,
System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ppComm,
ppRelatv, ppProd, ppClass, ppReport, Vcl.StdCtrls;

type
TForm5 = class(TForm)
ppReport1: TppReport;
Button1: TButton;
procedure ppReport1PrintDialogCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form5: TForm5;

implementation

{$R *.dfm}

procedure TForm5.Button1Click(Sender: TObject);
begin
ppreport1.Print;
end;

procedure TForm5.ppReport1PrintDialogCreate(Sender: TObject);
var
I : Integer;
begin
ShowMessage('Printing not allowed in the trial version.');
//
// Code to prevent the print dialog from showing goes here
//
// Here is the workaround until a different solution is found
//
for I := 0 to ppReport1.PrintDialog.ComponentCount -1 do
if (ppReport1.PrintDialog.Components[i] is TButton) then
begin
(ppReport1.PrintDialog.Components[i] as TButton).Enabled := False;
end;
end;
end;

end.
//===========================================================

--
Michael Riley
Marine Corps Gunnery Sergeant (Retired)
www.zilchworks.com

Comments

  • edited December 2014
    Hi Michael,

    You can access all the toolbar buttons using the Report.PreviewForm
    property typecasted as a TppPrintPreview object. Below is some sample
    code...

    uses
    ppPrvDlg;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    ppReport1.Print;

    end;

    procedure TForm1.ehPrintButton_Click(aSender: TObject);
    begin
    ShowMessage('Printing not allowed');

    end;

    procedure TForm1.ppReport1PreviewFormCreate(Sender: TObject);
    begin
    TppPrintPreview(ppReport1.PreviewForm).PrintButton.OnClick :=
    ehPrintButton_Click;

    end;

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited December 2014
    Nico Cizik (Digital Metaphors) wrote:


    Thank you Nico. This will work perfectly.

    --
    Michael Riley
    Marine Corps Gunnery Sergeant (Retired)
    www.zilchworks.com
This discussion has been closed.