whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

36 Visitors Online


 
...create menuitems at runtime?
Autor: Motzi
Homepage: http://www.delphi-area.de
[ Print tip ]  

Tip Rating (11):  
     


{
  When you click on button1 the number of installed fonts
  are displayed in the menu by creating the menuitems dynamically
  
  Zur Laufzeit wird die Anzahl der installierten Schriften ausgelesen und
  entsprechend viele Menüpunkte erzeugt
}

type
  
TForm1 = class(TForm)
    Button1: TButton;
    label1: TLabel;
    MainMenu1: TMainMenu;
    Fonts1: TMenuItem;
    procedure Fonts1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    
{ Private declarations }
  
public
    
{ Public declarations }
  
end;

var
  
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Fonts1Click(Sender: TObject);
begin
  if 
Sender  Fonts1 then
    
label1.Caption := (Sender as TMenuItem).Caption;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  
NewItem: TMenuItem;
  i: Integer;
begin
  for 
i := 0 to Screen.Fonts.Count - 1 do
  begin
    
// Create a new Menu Item
    // Neuen Menüpunkt erzeugen
    
NewItem := TMenuItem.Create(Self);
    // Take the Font name as Caption
    // Den Schriftnamen als Caption festlegen
    
NewItem.Caption := Screen.Fonts.Strings[i];
    // Assign a OnClick-Event
    // Ein OnClick-Ereignis zuweisen
    
NewItem.OnClick := Fonts1Click;
    // Add the new menu
    // Den neuen Menüpunkt hinzufügen
    
Fonts1.Add(NewItem);
  end;
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners