0

I am using Delphi XE2 . In the main window of my program I have a ribbon, I created the ribbontabs and ribbon panels and have shares in the groups. Also, in another window I have a TreeView in which I set the access for each user to the ribbon , giving two possibilities for each action : Hide or Disable. The problem occurs when hidden actions , I do it dynamically by accessing the application. When minimizing and maximizing the Ribbon hidden actions appear again.

This is my code:

PAS:

    unit Example;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ToolWin, Vcl.ActnMan, Vcl.ActnCtrls,
  Vcl.Ribbon, Vcl.RibbonLunaStyleActnCtrls, Vcl.ActnList, Vcl.StdCtrls;

type
  TFormExample = class(TForm)
    ActionManagerExample: TActionManager;
    Ribbon1: TRibbon;
    RibbonPage1: TRibbonPage;
    RibbonPage2: TRibbonPage;
    RibbonGroup1: TRibbonGroup;
    RibbonGroup2: TRibbonGroup;
    RibbonGroup3: TRibbonGroup;
    RibbonGroup4: TRibbonGroup;
    Action1: TAction;
    Action2: TAction;
    Action3: TAction;
    Action4: TAction;
    Action5: TAction;
    Action6: TAction;
    Action7: TAction;
    Action8: TAction;
    Action9: TAction;
    Action10: TAction;
    ButtonClickMe: TButton;
    procedure ButtonClickMeClick(Sender: TObject);
    procedure Action1Execute(Sender: TObject);
    procedure Action2Execute(Sender: TObject);
    procedure Action3Execute(Sender: TObject);
    procedure Action4Execute(Sender: TObject);
    procedure Action5Execute(Sender: TObject);
    procedure Action6Execute(Sender: TObject);
    procedure Action7Execute(Sender: TObject);
    procedure Action8Execute(Sender: TObject);
    procedure Action9Execute(Sender: TObject);
    procedure Action10Execute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormExample: TFormExample;

implementation

{$R *.dfm}

procedure TFormExample.Action10Execute(Sender: TObject);
begin
  ShowMessage('Action 10');
end;

procedure TFormExample.Action1Execute(Sender: TObject);
begin
  ShowMessage('Action 1');
end;

procedure TFormExample.Action2Execute(Sender: TObject);
begin
  ShowMessage('Action 2');
end;

procedure TFormExample.Action3Execute(Sender: TObject);
begin
  ShowMessage('Action 3');
end;

procedure TFormExample.Action4Execute(Sender: TObject);
begin
  ShowMessage('Action 4');
end;

procedure TFormExample.Action5Execute(Sender: TObject);
begin
  ShowMessage('Action 5');
end;

procedure TFormExample.Action6Execute(Sender: TObject);
begin
  ShowMessage('Action 6');
end;

procedure TFormExample.Action7Execute(Sender: TObject);
begin
  ShowMessage('Action 7');
end;

procedure TFormExample.Action8Execute(Sender: TObject);
begin
  ShowMessage('Action 8');
end;

procedure TFormExample.Action9Execute(Sender: TObject);
begin
  ShowMessage('Action 9');
end;

procedure TFormExample.ButtonClickMeClick(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to ActionManagerExample.ActionCount - 1 do
  begin
    if ActionManagerExample.Actions[i] is TCustomAction then
      TCustomAction(ActionManagerExample.Actions[i]).Visible := False;
  end;
end;

end.

DFM

    object FormExample: TFormExample
  Left = 0
  Top = 0
  Caption = 'Example'
  ClientHeight = 356
  ClientWidth = 699
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Ribbon1: TRibbon
    Left = 0
    Top = 0
    Width = 699
    Height = 143
    ActionManager = ActionManagerExample
    Caption = 'SSCCE'
    Tabs = <
      item
        Caption = 'Page 1'
        Page = RibbonPage1
      end
      item
        Caption = 'Page 2'
        Page = RibbonPage2
      end>
    ExplicitLeft = 480
    ExplicitTop = 72
    ExplicitWidth = 0
    DesignSize = (
      699
      143)
    StyleName = 'Ribbon - Luna'
    object RibbonPage2: TRibbonPage
      Left = 0
      Top = 50
      Width = 698
      Height = 93
      Caption = 'Page 2'
      Index = 1
      object RibbonGroup3: TRibbonGroup
        Left = 4
        Top = 3
        Width = 56
        Height = 86
        ActionManager = ActionManagerExample
        Caption = 'Group 3'
        GroupIndex = 0
      end
      object RibbonGroup4: TRibbonGroup
        Left = 62
        Top = 3
        Width = 56
        Height = 86
        ActionManager = ActionManagerExample
        Caption = 'Group 4'
        GroupIndex = 1
      end
    end
    object RibbonPage1: TRibbonPage
      Left = 0
      Top = 50
      Width = 698
      Height = 93
      Caption = 'Page 1'
      Index = 0
      object RibbonGroup1: TRibbonGroup
        Left = 4
        Top = 3
        Width = 56
        Height = 86
        ActionManager = ActionManagerExample
        Caption = 'Group 1'
        GroupIndex = 0
      end
      object RibbonGroup2: TRibbonGroup
        Left = 62
        Top = 3
        Width = 62
        Height = 86
        ActionManager = ActionManagerExample
        Caption = 'Group 2'
        GroupIndex = 1
      end
    end
  end
  object ButtonClickMe: TButton
    Left = 80
    Top = 200
    Width = 337
    Height = 97
    Caption = 'Click me and then minimize and maximize the ribbon'
    TabOrder = 1
    OnClick = ButtonClickMeClick
  end
  object ActionManagerExample: TActionManager
    ActionBars = <
      item
        Items = <
          item
            Action = Action1
            Caption = 'A&ction 1'
          end
          item
            Action = Action2
            Caption = '&Action 2'
          end
          item
            Action = Action3
            Caption = 'Ac&tion 3'
          end>
        ActionBar = RibbonGroup3
      end
      item
        Items = <
          item
            Action = Action4
            Caption = '&Action 4'
          end
          item
            Action = Action5
            Caption = 'A&ction 5'
          end
          item
            Action = Action6
            Caption = 'Ac&tion 6'
          end>
        ActionBar = RibbonGroup4
      end
      item
        Items = <
          item
            Action = Action7
            Caption = '&Action 7'
          end
          item
            Action = Action8
            Caption = 'A&ction 8'
          end
          item
            Action = Action9
            Caption = 'Ac&tion 9'
          end>
        ActionBar = RibbonGroup1
      end
      item
        Items = <
          item
            Action = Action10
            Caption = '&Action 10'
          end>
        ActionBar = RibbonGroup2
      end>
    Left = 528
    Top = 200
    StyleName = 'Ribbon - Luna'
    object Action1: TAction
      Caption = 'Action 1'
      OnExecute = Action1Execute
    end
    object Action2: TAction
      Caption = 'Action 2'
      OnExecute = Action2Execute
    end
    object Action3: TAction
      Caption = 'Action 3'
      OnExecute = Action3Execute
    end
    object Action4: TAction
      Caption = 'Action 4'
      OnExecute = Action4Execute
    end
    object Action5: TAction
      Caption = 'Action 5'
      OnExecute = Action5Execute
    end
    object Action6: TAction
      Caption = 'Action 6'
      OnExecute = Action6Execute
    end
    object Action7: TAction
      Caption = 'Action 7'
      OnExecute = Action7Execute
    end
    object Action8: TAction
      Caption = 'Action 8'
      OnExecute = Action8Execute
    end
    object Action9: TAction
      Caption = 'Action 9'
      OnExecute = Action9Execute
    end
    object Action10: TAction
      Caption = 'Action 10'
      OnExecute = Action10Execute
    end
  end
end

Anyone know how I can do to remain hidden ? happens internally in this film that makes stocks appear ?

Excuse this ribbon brings me many problems and has many bugs . But want to implement in my work . :-(

Nige Jones
  • 237
  • 3
  • 5
jmontegrosso
  • 89
  • 1
  • 11
  • That couldn't possibly be real code, it won't compile. – Jerry Dodge Jun 03 '14 at 13:24
  • Don't use `is` and `as` together. It's either `is` followed by a hard cast (like `TCustomAction(ActionManagerKiPrinc.Actions[I])`) or `as` with some error handling. – Uli Gerhardt Jun 03 '14 at 13:29
  • Where is the code you've posted being executed? Have you tried using the debugger to see what's happening? You're really not providing information we can use (we don't have your whole application with all of its code and the ribbon you've built to use for testing), and we can't see your screen or read your mind. As we've discussed before, *create a small test app that reproduces the issue*, and include it in your question. – Ken White Jun 03 '14 at 13:36
  • @JerryDodge: The code compiles fine here in XE6. What issue do you see where it won't compile? – Ken White Jun 03 '14 at 13:41
  • @Ken Missing a `.` before `Visible` but might compile depending on the context of the code. Also `: =` should be `:=` – Jerry Dodge Jun 03 '14 at 13:44
  • @ Ken do not need an entire application. Just hidden actions .. and when minimize and maximize the ribbon hidden actions appear again. In one of my previous post I put all code. and you said it proved. Try to hide actions with the code I give you. – jmontegrosso Jun 03 '14 at 13:51
  • Steps to get the error: 1 - Have a ribbon with actions 2 - Browse TActionManager Actions component (with the code provided above) and set the Visible property = False (at runtime). 3 - Minimize the Ribbon, then maximize the ribbon (at runtime). Actions appear or remain invisible? I use delphi xe2. – jmontegrosso Jun 03 '14 at 14:00
  • Why should we build an application to try to reproduce your code? I for one have no inclination in spending the time that it takes to do that. Most likely it will turn out that your code looks different from the code that I would build. Frankly, if you want us to help, you need to learn to help yourself. That means that you must put a lot more effort into asking the question. Do you care about this? If so, care enough to put in the effort required to make us care. Step 1, provide a good SSCCE. – David Heffernan Jun 03 '14 at 14:12
  • I add a good SSCCE. I am using Delphi XE2 Update 3 – jmontegrosso Jun 03 '14 at 14:42
  • Thank you very much. I personally cannot help because I don't have the package with the ribbon installed into my Delphi because I only install a minimal set of packages. I'm sure somebody else will help though. – David Heffernan Jun 03 '14 at 14:46
  • Note for testers: You have to add an Application Menu in order for the ribbon context menu to appear, which allows you to minimize/maximize the ribbon. It's not included in the SSCCE. – Ken White Jun 03 '14 at 15:38
  • @Jerry: I can't reproduce this (XE5 and XE6) once I fix your SSCCE to include the Application Menu (which is required in order to see the right-click menu that allows minimizing/maximizing of the ribbon). I run the app, click the large button (which causes the actions to all disappear), minimize/maximize the ribbon, and there are still no visible actions in the ribbon groups. – Ken White Jun 03 '14 at 15:40
  • I've managed to reproduce it. After minimizing the ribbon, click on a menu item (Page 1, for instance) instead of right-clicking and restoring the ribbon, and the actions all become visible again. Not sure what's causing it, but I can reproduce it. – Ken White Jun 03 '14 at 15:45
  • Double-clicking on the title pages of the Ribbon is minimized. No need to add the menu – jmontegrosso Jun 03 '14 at 19:14

1 Answers1

2

This seems to be coming from TCustomRibbonGroup.ShowControls (in Ribbon.pas). It loops through the controls in the group and sets each to visible if it isn't a descendant of TCustomToolScrollBtn):

procedure TCustomRibbonGroup.ShowControls;
var
  I: Integer;
begin
  for I := 0 to ControlCount - 1 do
  begin
    if Controls[I] <> nil then
      Controls[I].Visible := not Controls[I].InheritsFrom(TCustomToolScrollBtn);
  end;
end;

I believe the reason this happens is because the design guidelines state that you're not supposed to hide/show items in a group, but are supposed to enable/disable them instead and leave them visible to the user so that things don't appear and disappear from where they're expected to be found. From the Microsoft Ribbon Guidelines (emphasis added):

Disable commands that don't apply to the current context, or that would directly result in an error. If helpful, use the enhanced tooltip to explain why the command is disabled. Don't hide such commands because doing so can cause the ribbon layout to change, making the ribbon presentation unstable.

Ken White
  • 123,280
  • 14
  • 225
  • 444