Search code examples
delphidevexpressribbon

How to disable controls in a TdxRibbon (DevExpress ribbon control)?


I have a DevExpress VCL ribbon in my Delphi app From time to time the app is doing some updates and in that period I need to be sure that the user doesn't do anything so I would like to be able to disable all controls on the ribbon but I can't get the count of controls on each tab to work

The ComponentCount returns 0 regardless how I do but I can see controls. My testcode is looking like this:

procedure TfrmMain.RibbonDisable(var aMessage: TMessage);
var
  i: integer;
begin
  try
    for i := 0 to ribMain.TabCount - 1 do
      begin
        ribMain.Tabs.Items[i].Active := True;
        ShowMessage(IntToStr(ribMain.ActiveTab.ComponentCount));
      end;
  except
    on E:exception do
      Logfile.Error('frmMain.RibbonDisable: ' + E.Message);
  end;
end;

Solution

  • Simply disable the whole TdxRibbon while the updates are being performed:

    ribMain.Enabled := False;
    

    Or if you really want to disable only the tab items, use the following:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to ribMain.BarManager.ItemCount - 1 do
        ribMain.BarManager.Items[I].Enabled := False;
    end;
    

    It is common to almost every toolbar control that you are disabling actions, not what is displayed.