RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TMenuItem.Items Property

Lists the menu items in the submenu of the menu item.

Pascal
property Items [Index: Integer]: TMenuItem;
C++
__property TMenuItem Items[int Index];

Use Items to access to a subitem by its position in the list of subitems. The value of Index is the position of the subitem within the Items array. For example, if an application has a File drop-down menu that contains the menu items New, Open, and Save, in that order, the expression

FileMenu.Items[2]

 

FileMenu->Items[2] 

refers to the Save command.

Note: In Delphi, Items is the default property for TMenuItem. This means you can leave off the property name. Thus, instead of writing FileMenu.Items[2], you can write FileMenu[2].
Note: In C++, Items can be accessed using the [] operator, to achieve an affect similar to the default property in Delphi.
 

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!