Plugin not working in RB7?
Hi,
I've downloaded the HidePrintButton plugin example, but it's not working
correctly. When I'm trying to hide the print button, the entire toolbar
doesn't have any buttons.
So I expanded the example to view/hide the other buttons by constructing
a small procedure within my (registered) preview class. Trying to hide
some of the other buttons simply has no effect - they're still visible.
Trying to hide the print button still gives the result mentioned above.
Is this approach incompatible with V7.04, or is the example just
incomplete?
TIA,
Michael
--- Here goes my code ---
unit uRepPreview;
interface
uses
Buttons, StdCtrls, ppPreview, ppTypes;
type
TPreviewPlugin1 = class(TppPreview)
private
function GetSpeedButtonForPreviewAction(aPreviewAction:
TppPreviewActionType): TSpeedButton;
procedure EnableAction(aPreviewAction: TppPreviewActionType; V:
boolean);
public
procedure BeforePreview; override;
end;
implementation
uses
Graphics, SysUtils, Controls;
function TPreviewPlugin1.GetSpeedButtonForPreviewAction(aPreviewAction:
TppPreviewActionType): TSpeedButton;
var
x: integer;
C: TControl;
begin
Result := nil;
x := 0;
while (Result = nil) and (x < Toolbar.ControlCount) do begin
C := Toolbar.Controls[x];
if (C.Tag = Ord(aPreviewAction)) then Result := TSpeedButton(C)
else Inc(x);
end;
end;
procedure TPreviewPlugin1.EnableAction(aPreviewAction:
TppPreviewActionType; V: boolean);
var
spbtnAction: TSpeedButton;
begin
case aPreviewAction of
paPrint,
paAutoSearch,
paTextSearch,
paWholePage,
paPageWidth,
pa100Percent,
paFirst,
paPrior,
paNext,
paLast,
paClose,
paGoToPage:
begin
spbtnAction := GetSpeedButtonForPreviewAction(aPreviewAction);
if spbtnAction <> nil then spbtnAction.Visible := V;
end;
end;
end;
procedure TPreviewPlugin1.BeforePreview;
var
btnPrint: TSpeedButton;
begin
inherited BeforePreview;
// won't work, entire toolbar is empty
EnableAction(paPrint, false);
// won't work, simply has no effect
EnableAction(paPageWidth, false);
end;
initialization
TppPreviewPlugIn.Register(TPreviewPlugin1);
finalization
TppPreviewPlugIn.UnRegister(TPreviewPlugin1);
end.
I've downloaded the HidePrintButton plugin example, but it's not working
correctly. When I'm trying to hide the print button, the entire toolbar
doesn't have any buttons.
So I expanded the example to view/hide the other buttons by constructing
a small procedure within my (registered) preview class. Trying to hide
some of the other buttons simply has no effect - they're still visible.
Trying to hide the print button still gives the result mentioned above.
Is this approach incompatible with V7.04, or is the example just
incomplete?
TIA,
Michael
--- Here goes my code ---
unit uRepPreview;
interface
uses
Buttons, StdCtrls, ppPreview, ppTypes;
type
TPreviewPlugin1 = class(TppPreview)
private
function GetSpeedButtonForPreviewAction(aPreviewAction:
TppPreviewActionType): TSpeedButton;
procedure EnableAction(aPreviewAction: TppPreviewActionType; V:
boolean);
public
procedure BeforePreview; override;
end;
implementation
uses
Graphics, SysUtils, Controls;
function TPreviewPlugin1.GetSpeedButtonForPreviewAction(aPreviewAction:
TppPreviewActionType): TSpeedButton;
var
x: integer;
C: TControl;
begin
Result := nil;
x := 0;
while (Result = nil) and (x < Toolbar.ControlCount) do begin
C := Toolbar.Controls[x];
if (C.Tag = Ord(aPreviewAction)) then Result := TSpeedButton(C)
else Inc(x);
end;
end;
procedure TPreviewPlugin1.EnableAction(aPreviewAction:
TppPreviewActionType; V: boolean);
var
spbtnAction: TSpeedButton;
begin
case aPreviewAction of
paPrint,
paAutoSearch,
paTextSearch,
paWholePage,
paPageWidth,
pa100Percent,
paFirst,
paPrior,
paNext,
paLast,
paClose,
paGoToPage:
begin
spbtnAction := GetSpeedButtonForPreviewAction(aPreviewAction);
if spbtnAction <> nil then spbtnAction.Visible := V;
end;
end;
end;
procedure TPreviewPlugin1.BeforePreview;
var
btnPrint: TSpeedButton;
begin
inherited BeforePreview;
// won't work, entire toolbar is empty
EnableAction(paPrint, false);
// won't work, simply has no effect
EnableAction(paPageWidth, false);
end;
initialization
TppPreviewPlugIn.Register(TPreviewPlugin1);
finalization
TppPreviewPlugIn.UnRegister(TPreviewPlugin1);
end.
This discussion has been closed.
Comments
You're going to want to use the CreateToolBarControls routine to enable and
disable the buttons in the preview toolbar. I'm not sure why this example
is named the way it is but it definitely does not try to hide the print
button. Take a look at the following example instead.
http://www.digital-metaphors.com/tips/PreviewPrintBtnDisabled.zip
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com