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

How make the Print button on preview form invisible?

edited October 2004 in General
I am converting a D5 app to D7 and ReportBuilder 7. The following line
of code used to work to make the Print button on the preview form
invisible.

TppPrintPreview(Report.PreviewForm).spbPreviewPrint.Visible := False;

Now I get "undeclared identifier: 'spbPreviewPrint'".

How can I make the Print button invisible in RB 7?

Thanks,

--
_Bill_

Comments

  • edited October 2004
    To address that issue I have coded this few lines that give you access to
    any button on the preview form:

    TppPreviewButtonType = (pbPrint, pbAutoSearch, pbTextSearch, pbWholePage,
    pbPageWidth, pb100Percent, pbFirst, pbPrior,
    pbNext,
    pbLast, pbCancel, pbClose, pbGoToPage); // do not
    use pbCancel or pbClose


    // find a button on the preview Form
    function _FindTheButton(aButton: TppPreviewButtonType; StartAt:
    TPanel): TSpeedButton;
    function GetPreviewButton(aButtonType: TppPreviewButtonType; Sender:
    TObject): TSpeedButton;

    // disable/hide the print button on the pewview form
    procedure DisablePrintButton(Sender: TObject);
    procedure HidePrintButton(Sender: TObject);


    function _FindTheButton(aButton: TppPreviewButtonType; StartAt: TPanel):
    TSpeedButton;
    var
    i: integer;
    begin
    Result := nil;

    if aButton in [pbCancel, pbClose] then
    Exit;

    for i := 0 to StartAt.ControlCount-1 do
    begin
    if not Assigned(Result) then
    begin
    if StartAt.Controls[i] is TPanel then
    Result := _FindTheButton(aButton, StartAt.Controls[i] as TPanel)
    else
    if (StartAt.Controls[i].Tag = Ord(aButton)) and (StartAt.Controls[i]
    is TSpeedButton) then
    begin
    Result := TSpeedButton(StartAt.Controls[i]);
    Break;
    end;
    end
    else
    Break;
    end;
    end;
    // -------------------------------------------------------------------------
    ----
    //
    procedure DisablePrintButton(Sender: TObject);
    var
    btn: TSpeedButton;
    begin
    btn := GetPreviewButton(pbPrint,Sender);
    if Assigned(btn) then
    btn.Enabled := False;
    end;
    // -------------------------------------------------------------------------
    ----
    //
    procedure HidePrintButton(Sender: TObject);
    var
    btn: TSpeedButton;
    begin
    btn := GetPreviewButton(pbPrint,Sender);
    if Assigned(btn) then
    btn.Visible := False;
    end;
    // -------------------------------------------------------------------------
    ----
    //
    function GetPreviewButton(aButtonType: TppPreviewButtonType; Sender:
    TObject): TSpeedButton;
    var
    i: integer;
    begin
    Result := nil;
    if aButtonType in [pbCancel, pbClose] then
    Exit;

    if not ((Sender is TppReport) and Assigned((Sender as
    TppReport).PreviewForm)) then
    Exit;
    for i := 0 to TppReport(Sender).PreviewForm.ControlCount-1 do
    if not Assigned(Result) then
    if TppReport(Sender).PreviewForm.Controls[i] is TPanel then
    Result :=
    _FindTheButton(aButtonType,TppReport(Sender).PreviewForm.Controls[i] as
    TPanel);
    end;
    // -------------------------------------------------------------------------
    ----
    //


    Put this code in some unit and use this methods on the OnPreviewFormCreate
    event of the Report.
    Sender parameter in this methods is always the Sender object passed in this
    event.

    Best regards,
    Nuno Fonseca




  • edited October 2004
    Hi Bill,

    The archetecture for the preview has changed a bit since RB 5. Now if you
    would like to change the preview form, you must create a preview plugin
    descendent that does so. Below is an example that shows how to use this
    method to hide the print button on the preview form...

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

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2004
    Nico,

    Every time I ask a question you have a canned example that is just what
    I need.:) Is there an index of these examples so I can find what I need
    myself?

    --
    _Bill_

  • edited October 2004
    Hi Bill,

    Thanks for the feedback. We use the "tips" directory mainly for user
    specific examples, but over time it has accumilated a number of examples
    that describe how to solve common issues. It is on our todo list to go
    through all these examples, debug them, write a description for each, and
    create a directory online for all of them.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.