Enabled Property (MenuItem Objects)

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

Use the MenuItem.Enabled property to find out whether the specified item is enabled.

Declaration

TestObj.Enabled

Read-Only Property Boolean
TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section

Applies To

The property is applied to the following object:

View Mode

To view this property in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Property Value

True, if the menu item is enabled. Otherwise - False.

Example

The following code snippet obtains the Status Bar item of the View menu in Windows Notepad and checks whether the menu item is enabled.

JavaScript, JScript

function MenuItemSample()
{
  var Notepad, Window, MainMenu, Submenu, Item;
  // Obtains the Windows Notepad main menu
  Notepad = Sys.Process("Notepad");
  Window = Notepad.Window("Notepad", "*");
  MainMenu = Window.MainMenu;

  // Obtains the View submenu
  Submenu = MainMenu.Items("View").SubMenu;

  // Obtains the "Status Bar" menu item
  Item = Submenu.Items("Status Bar");

  // Checks whether the item is enabled
  if (Item.Enabled)
    Log.Message("The Status Bar menu item is enabled");
  else
    Log.Message("The Status Bar menu item is disabled");

}

Python

def MenuItemSample():
  # Obtains the Windows Notepad main menu
  Notepad = Sys.Process("Notepad")
  Window = Notepad.Window("Notepad", "*")
  MainMenu = Window.MainMenu

  # Obtains the View submenu
  Submenu = MainMenu.Items["View"].SubMenu

  # Obtains the "Status Bar" menu item
  Item = Submenu.Items["Status Bar"]

  # Checks whether the item is enabled
  if (Item.Enabled):
    Log.Message("The Status Bar menu item is enabled")
  else:
    Log.Message("The Status Bar menu item is disabled")

VBScript

Sub MenuItemSample

  ' Obtains the Windows Notepad main menu
  Set Notepad = Sys.Process("Notepad")
  Set Window = Notepad.Window("Notepad", "*")
  Set MainMenu = Window.MainMenu

  ' Obtains the View submenu
  Set Submenu = MainMenu.Items("View").SubMenu

  ' Obtains the "Status Bar" menu item
  Set Item = Submenu.Items("Status Bar")

  ' Checks whether the item is enabled
  If Item.Enabled Then
    Log.Message "The Status Bar menu item is enabled"
  Else
    Log.Message "The Status Bar menu item is disabled"
  End If

End Sub

DelphiScript

procedure MenuItemSample();
var Notepad, Window, MainMenu, Submenu, Item;
begin
  // Obtains the Windows Notepad main menu
  Notepad := Sys.Process('Notepad');
  Window := Notepad.Window('Notepad', '*');
  MainMenu := Window.MainMenu;

  // Obtains the View submenu
  Submenu := MainMenu.Items('View').SubMenu;

  // Obtains the "Status Bar" menu item
  Item := Submenu.Items('Status Bar');

  // Checks whether the item is enabled
  if Item.Enabled then
    Log.Message('The Status Bar menu item is enabled')
  else
    Log.Message('The Status Bar menu item is disabled');

end;

C++Script, C#Script

function MenuItemSample()
{
  var Notepad, Window, MainMenu, Submenu, Item;
  // Obtains the Windows Notepad main menu
  Notepad = Sys["Process"]("Notepad");
  Window = Notepad["Window"]("Notepad", "*");
  MainMenu = Window["MainMenu"];

  // Obtains the View submenu
  Submenu = MainMenu["Items"]("View")["SubMenu"];

  // Obtains the "Status Bar" menu item
  Item = Submenu["Items"]("Status Bar");

  // Checks whether the item is enabled
  if (Item["Enabled"])
    Log["Message"]("The Status Bar menu item is enabled");
  else
    Log["Message"]("The Status Bar menu item is disabled");

}

See Also

Checking Menu Item's State in Desktop Windows Applications
Checked Property (MenuItem Objects)
IsSeparator Property (MenuItem Objects)

Highlight search results