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

Disabling Printing from the Preview Window.

edited July 2002 in General
How can I disable the Print button in the print preview?
or barring that, How can I stop the print job from going to the printer?

I have tried putting a Report.Cancel or a Report.PageLimitReached in the
BeforePrint but the print job is still being sent to the printer.

Thanks in advance,

Trevor Bourget

Comments

  • edited July 2002
    Check out the demo below for an example of customizing the preview.

    http://www.digital-metaphors.com/tips/CustomPreview.zip

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

  • edited July 2002
    Thanks. The demo was great. However, I only need to disable the Print button
    in the preview some of the time. How can I have Report Builder use the
    custom form sometimes and the actual form the rest of the time?

    My problem is that in some areas of my program I need to control when they
    can print the report. Yet I still would like to use the print preview to
    allow them to view the report. In other areas of the program they can print
    with impunity. From my understanding of the demo, Report Builder will use
    the Custom Print Preview all the time.

    Thanks,
    Trevor Bourget

    "Alexander Kramnik (Digital Metaphors)" wrote
  • edited July 2002
    Why no just add a public property to your customized form which you can
    toggle to specify whether the button should be shown. Then you don't have to
    worry about switching up forms and only use one.

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

  • edited July 2002
    I have come accross a problem adding the property. In the procedure where i
    set the visible property of the Print Button I am getting a memory access
    error. When I debug it I can see the value for the visible property but the
    button itself reads as inaccessable.

    Here is the code that I added:
    public:
    property ShowPrintButton : boolean read GetPrintVisible write
    SetPrintVisible;

    implementation
    function TmyPreview.GetPrintVisible : boolean;
    begin
    if assigned(FBtnPrint) then result := FBtnPrint.Visible
    else
    Result := False;
    end; //

    procedure TmyPreview.SetPrintVisible(PrintVisible :boolean);
    begin
    FBtnPrint.Visible := PrintVisible;
    blnPrintVisible := PrintVisible;
    end; // SetPrintVisible


  • edited July 2002
    At what point are you setting this property. I would recommend doing it in
    the Report.OnPreviewFormCreate event. btw. what is 'blnPrintVisible '.

    PS. The getter could be simplified as below:

    Result := (FBtnPrint<> nil) and (FBtnPrint.Visible);

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

  • edited August 2002
    As per your suggestion i put the following line of code in the
    Report.OnPreviewFormCreate:
    TmyPreview(rptLabel.PreviewForm).ShowPrintButton := False;

    However when i step into the SetPrintVisible (provided below), FbtnPrint is
    nil, yet i have a breakpoint at the FBtnPrint :=
    TSpeedButton.Create(FToolbar); line which gets tripped before
    SetPrintVisible is even called.

    How can this be?

    Thanks,
    Trevor Bourget

    PS. The blnPrintVisible is just a flag I have made.

    "Alexander Kramnik (Digital Metaphors)" wrote
  • edited August 2002
    Check your code to see if there are any places where the button could be
    getting nilled out. Try following the progress of the program by stepping
    over code from the point where the button gets created. It's possible that
    for some reason you might be looking at two different instances of the
    preview form, one of then not having been initialized.

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

This discussion has been closed.