RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TMenuItem.Enabled Property

Specifies whether the menu item is enabled.

Pascal
property Enabled: Boolean;
C++
__property Boolean Enabled;

Use Enabled to enable or disable a menu item. If Enabled is true, the Click method is called when the user selects the item with the mouse. If Enabled is false, the menu item appears dimmed and the user cannot select it. However, calling the Click method works even when Enabled is false.

Note: This property is not stored with the menu item if it is supplied by a TAction object.
 

C++ Examples: 

 

/*
The following code disables all the subitems of of the menu
item File1.  This example requires a button, a TMainMenu
with several menu items added, one of them named File1.
*/
void __fastcall TForm1::DisableSubItemsClick(TObject *Sender)
{
  for (int i = 0; i < File1->Count; i++)
  {
    File1->Items[i]->Enabled = false;
  }
}

void __fastcall TForm1::Edit1Click(TObject *Sender)
{
  ListBox1->Items->Add("This is the Edit command");
}

void __fastcall TForm1::File1Click(TObject *Sender)
{
  ListBox1->Items->Add("This is the File command");
}

void __fastcall TForm1::FileSub11Click(TObject *Sender)
{
  ListBox1->Items->Add("This is the FileSub1 command");
}

void __fastcall TForm1::FileSub21Click(TObject *Sender)
{
  ListBox1->Items->Add("This is the FileSub2 command");
}

void __fastcall TForm1::FileSub31Click(TObject *Sender)
{
  ListBox1->Items->Add("This is the FileSub3 command");
}

void __fastcall TForm1::Options1Click(TObject *Sender)
{
  ListBox1->Items->Add("This is the Options command");
}

 

Delphi Examples: 

{
The following code disables all the subitems of of the menu
item File1.  This example requires a button, a TMainMenu
with several menu items added, one of them named File1.
} 
procedure TForm1.DisableSubItemsClick(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to File1.Count - 1 do
    File1.Items[I].Enabled := False;
end;

procedure TForm1.Edit1Click(Sender: TObject);
begin
  ListBox1.Items.Add('This is the Edit command');
end;

procedure TForm1.File1Click(Sender: TObject);
begin
  ListBox1.Items.Add('This is the File command');
end;

procedure TForm1.FileSub11Click(Sender: TObject);
begin
  ListBox1.Items.Add('This is the FileSub1 command');
end;

procedure TForm1.FileSub21Click(Sender: TObject);
begin
  ListBox1.Items.Add('This is the FileSub2 command');
end;

procedure TForm1.FileSub31Click(Sender: TObject);
begin
  ListBox1.Items.Add('This is the FileSub3 command');
end;

procedure TForm1.Options1Click(Sender: TObject);
begin
  ListBox1.Items.Add('This is the Options command');
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!