was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

48 Visitors Online


 
...Menüpunkte zur Laufzeit erzeugen?
Autor: Motzi
Homepage: http://www.delphi-area.de
[ Tip ausdrucken ]  

Tip Bewertung (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;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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