//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "FormCount.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: FormCount
// Property: Menus.TMenu.Items
// Property: Forms.TScreen.FormCount
// Property: Forms.TScreen.Forms
// Method: Menus.TMenuItem.Add
// Method: Menus.TMenuItem.Create
// Property: Menus.TMenuItem.Caption

// BeginCode
/*
This example assumes that the main form of the application
has a main menu with a menu item. The following code adds a
separator, and the name of all forms to the menu. Do not
access FormCount in the mainform's FormCreate.  The other
forms do not exist yet!
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TMenuItem *NewItem;
  // first create the separator
  NewItem = new TMenuItem(this); // If you change the AOwner (this) to MainMenu1->Items[1] and then you add the new menu you will get "Menu inserted twice"?  Doesn't happen in Delphi.
  NewItem->Name = "Separator";   // The owner will cleanup these menu items.
  NewItem->Caption = "-";
  // add the new item to the Windows menu
  MainMenu1->Items->Items[1]->Add(NewItem);
  // now create and add a menu item for each form
  for  (int I = 0; I < Screen->FormCount; I++)
  {
	NewItem = new TMenuItem(this); // The owner will cleanup these menu items.
	NewItem->Caption = Screen->Forms[I]->Name + "Item";
	NewItem->Name = Screen->Forms[I]->Name;
	MainMenu1->Items->Items[1]->Add(NewItem);
  }
}
// EndCode
// EndExample: FormCount
//---------------------------------------------------------------------------
