Disabling Print Button
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;
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;
This discussion has been closed.
Comments
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
http://www.digital-metaphors.com
info@digital-metaphors.com
--
Jeff Kreider