FormCount (Delphi)
From RAD Studio XE2 Code Examples
Language:
Description
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.
Code
procedure TForm1.Button1Click(Sender: TObject); var NewItem: TMenuItem; I : integer; begin { First create the separator. } NewItem := TMenuItem.Create(MainMenu1.Items[1]); NewItem.Name:= 'Separator'; NewItem.Caption := '-'; { Add the new item to the Windows menu. } MainMenu1.Items[1].Add(NewItem); { Now create and add a menu item for each form. } for I := 0 to Screen.FormCount-1 do begin NewItem := TMenuItem.Create(MainMenu1.Items[1]); NewItem.Caption := Screen.Forms[I].Name + 'Item'; NewItem.Name := Screen.Forms[I].Name; MainMenu1.Items[1].Add(NewItem); end; end; procedure TForm1.FormDestroy(Sender: TObject); var I : Integer; begin // Count down, not up. for I := MainMenu1.Items[1].Count - 1 downto 0 do begin MainMenu1.Items[1].Items[I].Free; end; end;
Uses
- Vcl.Menus.TMenu.Items ( fr | de | ja )
- Vcl.Forms.TScreen.FormCount ( fr | de | ja )
- Vcl.Forms.TScreen.Forms ( fr | de | ja )
- Vcl.Menus.TMenuItem.Add ( fr | de | ja )
- Vcl.Menus.TMenuItem.Create ( fr | de | ja )
- Vcl.Menus.TMenuItem.Caption ( fr | de | ja )