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

Disabling Toolbars and Menu items in the Report Designer

edited January 2006 in End User
I need to disable both the Standard ToolBar and File Open in the Designer
because I want my users to be able to customise only the open file and not
be able to open other files.

There was a similar question asked but the solution omits the units needed
for TppDesignerWindow and TppToolbar.

Please could you supply these for me. Thankyou

Previously asked question as below
-----------------------------------
The toolbars are not created until the window is first shown. Try using the
Designer.OnActivate event..

Example

var
lDesignerWindow: TppDesignerWindow;
lToolbar: TppToolbar;
begin

if (FFirstTime) then // use a boolean to perform this only once
begin
lDesignerWindow := TppDesignerWindow(ppDesigner1.Form);
lToolbar := lDesignerWindow.ToolbarManager.FindToolbar('Standard');
lToolbar.Enabled := False;

FFirstTime := False;
end;



Comments

  • edited January 2006
    Hi Rhonda,

    The easiest way to find out where a class is declared is to perform a Search
    | Find in Files... from Delphi in the \RBuilder\Source directory for " = class".

    TppDesignerWindow: ppDsgner.pas
    TppToolbar: ppToolbars.pas

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2006
    Sorry, if you are using RB 7.x or earlier,

    TppToolbar is located in the ppTB97x.pas file.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2006
    This code does not compile/work in version 10.

    Please advise. I am looking to hide/control toolbars in the TppDesigner and
    this looked like a starting point.

  • edited February 2006


    Here is a downloadable example that shows how to customize the menu and
    toolbar items in RB 10.

    www.digital-metaphors.com/tips/Designer10_CustomizeMenusAndToolbars.zip

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited February 2006
    Nard

    Thanks for the code. However, it does not solve my problem completely . We
    need to restrict the user from searching for and opening reports. we can
    provide our own menu with the mergemenu functionality, but then we need to
    remove the "Standard" toolbar. If I hide the toolbar, all the user needs to
    do is open to toolbars menu and turn the "Standard" toolbar on again. I then
    tried replacing the actions for the buttons (replacing the
    GetActionForName('').execute with my custom action), but that does not seem
    to take hold.

    I can disable the toolbar so if it gets turned on again, it will not
    respond. Is there an easier way. It seems being able to replace the file
    menu is nice, but not being table to manipulate the toolbars limits the
    power of the mergemenu power.

    Finally, I want to automatically open the "Data Wizard" when the user
    selects the data tab, and there is no data map that already exists. Is this
    possible.

    Thanks in advance

    Mark

    My options right now are to disable the toolbar
  • edited February 2006

    I'm working on an example that will show how to customize a bit more...



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited March 2006

    Dear Sir ,

    We are as well trying to set the menu's and toolbars dynamic. For
    example we want to hiide the "Open" button of the "Standard" toolbox. In
    this we succeed, see sample code __ReportDesignerHideToolbars hereafter.

    However, we do not succeed to hide some of the File menu items. questions:

    1) The SaveFile and Loadfrom file we can not hide. To do a test we have
    a routine that sets all items of the filemenu to invisible. But
    unfortunately the Savetofile and loadfromfile are still shown. If we
    report the status of the menu items with a OnDeactivate event, these
    items show a visible status as well. We try to set the visibility on the
    ON Activate event as you can see in the code. It looks like these two
    menu items are set to visible after the ONActivate event?

    2) How can we access the menu of the Data tabsheet?

    Pls help. We use Delphi 7 and Reportbuilder 10.01

    Regards,




    procedure TForm1.__SetReportDesignerDefaults(aReportDesigner: TppDesigner);

    begin
    aReportDesigner.OnActivate := __OnReportDesignerActivate;
    aReportDesigner.OnDeactivate := __OnReportDesignerDeActivate;

    .... >


    end;

    procedure TForm1.__OnReportDesignerDeActivate(Sender: TObject);
    begin
    mmDebug.Lines.Add('<-- __OnReportDesignerDeActivate -->');
    __PrintReportDesignerValues(ppDesignerGlobal, false);
    end;


    procedure TForm1.__OnReportDesignerActivate(Sender: TObject);
    begin
    if ppReportDesignerFirstTime then
    begin
    ppReportDesignerFirstTime := false;
    mmDebug.Lines.Add('<-- __OnReportDesignerActivate -->');
    __ReportDesignerHidePrintFileMenuItems(ppDesignerGlobal);
    __ReportDesignerHideToolbars(ppDesignerGlobal);
    __PrintReportDesignerValues(ppDesignerGlobal, false);
    end;
    end;

    procedure TForm1.__ReportDesignerHidePrintFileMenuItems(aReportDesigner:
    TppDesigner);
    var i: integer;
    begin
    for i := 0 to aReportDesigner.Menu.Items.Items[FileMenu].Count - 1 do
    begin
    aReportDesigner.Menu.Items.Items[FileMenu].Items[i].Visible := false;
    end;
    end;

    {*
    Hiding of toolbars have to be on in the OnActivate event of the designer
    Since they are created after showing the firts window of the designer
    *}

    procedure TForm1.__ReportDesignerHideToolbars(aReportDesigner: TppDesigner);
    var
    lDesignerWindow: TppDesignerWindow;
    lToolbar: TppToolbar;
    i, j, k: integer;
    pVisible: string;
    begin

    lDesignerWindow := TppDesignerWindow(aReportDesigner.Form);

    // Find the "Standard" toolbar and set the "Open" button to invisible
    for i := 0 to
    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Count - 1 do
    begin

    mmDebug.Lines.Add(lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].Caption
    + ' ** ' +
    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].Name
    + ' ** ' +
    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].ClassName
    );
    if
    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].Name =
    'Standard' then
    begin
    for j := 0 to
    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].Items.Count
    - 1 do
    begin
    mmDebug.Lines.Add(
    ' ' +
    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].Items.Items[j].Caption
    + ' ** ' +
    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].Items.Items[j].Name
    + ' ** ' +
    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].Items.Items[j].ClassName
    );
    if
    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].Items.Items[j].Caption
    = 'Open' then
    begin

    lDesignerWindow.LayoutManager.ToolManager.Toolbars.Items[i].Items.Items[j].Visible
    := false;
    end;
    end;
    end;
    end;


    // the following two lines would set the "Standard" toolbar to invisile
    and remove this toolbar from the toggle seelction in the menu
    (*

    lDesignerWindow.LayoutManager.ToolManager.Toolbars.ItemsByName['Standard'].Visible
    := false;

    lDesignerWindow.LayoutManager.ToolManager.RemoveToolbar(lDesignerWindow.LayoutManager.ToolManager.Toolbars.ItemsByName['Standard']);
    *)

    end;



    procedure TForm1.__PrintReportDesignerValues(aReportDesigner:
    TppDesigner; MemoClear: boolean);
    var i: integer;
    pvisible: string;

    begin
    if MemoClear then
    mmDebug.Clear;


    for i := 0 to aReportDesigner.Menu.Items.Items[FileMenu].Count - 1 do
    begin
    if aReportDesigner.Menu.Items.Items[FileMenu].Items[i].Visible then
    pvisible := 'T'
    else
    pvisible := 'F'
    ;

    mmDebug.Lines.Add(aReportDesigner.Menu.Items.Items[FileMenu].Items[i].Caption
    + ' ' +
    aReportDesigner.Menu.Items.Items[FileMenu].Items[i].ClassName
    + ' ' + aReportDesigner.Menu.Items.Items[FileMenu].Items[i].Name
    + ' visible: ' + pvisible
    );

    end;
    end;
  • edited March 2006
    Solved the menu item for the savetofile and readfromfile :)

    This is controlled by the TppDesigner.AllowSaveToFile property. By
    adding this to the code, the File menu is now empty.


    One question remains:

    How to access the menu items for the data tabsheet, this I don not succeed.

    regards,


    procedure TForm1.__SetReportDesignerDefaults(aReportDesigner: TppDesigner);
    var i: integer;
    lMenuBar: TppMenuBar;
    { lFileMenu: TppTBCustomItem;}
    lDesignerMenu: TppDesignerMenu;

    begin
    __PrintReportDesignerValues(aReportDesigner, true);

    aReportDesigner.OnActivate := __OnReportDesignerActivate;
    aReportDesigner.OnDeactivate := __OnReportDesignerDeActivate;
    aReportDesigner.AllowSaveToFile := false;

    ------->

    end;
  • edited March 2006

    Please post with your full name, rather than 'smouge.' This is a requirement
    of our newsgroups.
    Please see the support section of our web site for the newsgroup guidelines.

    1. This is a good example of customizing the design menu

    www.digital-metaphors.com/tips/Designer10_CustomizeMenusAndToolbars.zip

    2. To access the Data workspace menu, you need to use the
    Designer.OnTabChanged event as shown in the example below. Then you can use
    the Designer.Menubar property. When I tested this using RB 10.01, the timing
    of the event did not return the correct the ActivePageIndex. This will be
    fixed for RB 10.02.

    if ppDesigner1.Notebook.ActivePageIndex = 0 then
    ShowMessage('Data workspace selected');





    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.