Skip to main content

TdxRibbonContext.Activate(Boolean) Method

Activates the current context within the Ribbon.

Declaration

procedure Activate(AActivateFirstTab: Boolean = True);

Parameters

Name Type
AActivateFirstTab Boolean

Remarks

If a context’s Visible option is disabled, calling the Activate method automatically enables this option and selects the first tab within the tabs associated with this context.

If the current context is already active, pass False as the AActivateFirstTab parameter to prohibit selecting the first tab and preserve the currently selected tab.

End-users can click a contextual tab label to activate a corresponding context and select the first visible tab associated with this context.

The following code example shows how to activate contextual tabs in response to selection changes in a TRichEdit text editor. This example assumes that two contexts are created within the Ribbon’s Contexts collection at indexes 0 and 1, respectively. These contexts correspond to the ‘Text Tools’ and ‘Table Tools’ contextual tabs.

const
  TextToolsContext = 0;    // The 'Text Tools' context's index
  TableToolsContext = 1;   // The 'Table Tools' context's index
  TableEntryID = '#Table'; // Table identity string
// ...
// The editor's OnSelectionChange event handler
procedure <Form>.EditorSelectionChange(Sender: TObject);
begin
  // ...
  // Check whether a text is selected within the editor
  if Editor.SelLength > 0 then
  begin
    // Activating the 'Text Tools' context. Note that this context has
    // priority over the 'Table Tools' context if both contexts are available
    // simultaneously.
    Ribbon.Contexts[TextToolsContext].Activate(False);
    // Showing the 'Table Tools' contextual tabs if the selection contains the
    // table identity string
    Ribbon.Contexts[TableToolsContext].Visible :=
      Pos(TableEntryID, Editor.SelText) > 0;
  end else
  begin
    Ribbon.Contexts[TextToolsContext].Visible := False;
    Ribbon.Contexts[TableToolsContext].Visible := False;
  end;
end;
See Also