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

Disabling Print Button

edited February 2003 in General
I am using the code below to disable the print button under certain
conditions. However the end result is that all the speed buttons are
disabled or enabled, not the print button only. What do I need to fix to
make this work as I need it to?

Jeff Kreider


procedure TmyPreviewPlugIn.BeforePreview;
var lPrintButton: TSpeedButton;
begin
inherited BeforePreview;
lPrintButton := GetButtonForPreviewAction(paPrint);

if (lPrintButton = nil)
then
raise Exception.Create('TmyPreviewPlugIn.BeforePreview: Unable to find
print button.');
else
if FalseCondition then lPrintButton.Enabled := False;
end;

function TmyPreviewPlugIn.GetButtonForPreviewAction(aPreviewAction:
TppPreviewActionType): TSpeedButton;
var
liIndex: Integer;
lControl: TControl;
begin
Result := nil;
liIndex := 0;
while (Result = nil) and (liIndex < Toolbar.ControlCount) do begin
lControl := Toolbar.Controls[liIndex];
if (lControl.Tag = Ord(aPreviewAction))
then Result := TSpeedButton(lControl)
else inc(liIndex);
end;
end;

Comments

  • edited February 2003
    You are using RB 7.01. We added some panels and more controls to support the
    text search feature in the preview. The problem is that paPrint is the first
    value in the TppPreviewActionType enumerated type. Unfortunately, the tag
    value of the panel matches that of the print button. Additionally, there is
    no check in the code to make sure that the lControl was a TSpeedButton
    before typecasting it, so it returned a panel with the matching tag based on
    the Ord call on paPrint. It successfully typecasted the panel as aWhat you
    can do is either add a check (lControl is TSpeedButton) or use the new
    protected property to get at the preview button controls in RB 7.01, instead
    of having to use GetButtonForPreviewAction.


    procedure TmyPreviewPlugIn.BeforePreview;
    begin

    inherited BeforePreview;

    PrintButton.Visible := False;

    end;


    --
    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited February 2003
    Thanks Jim! I am using RB 7.01 and I like the simpler code as well.

    --
    Jeff Kreider

This discussion has been closed.