Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create a submenu at runtime Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Oct-02
Category
VCL-Menu
Language
Delphi 2.x
Views
57
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I have a menu item in a menu and would like to fill a submenu with items loaded at 
runtime.

Answer:

1   procedure TForm1.Button1Click(Sender: TObject);
2   var
3     aItem, aSubItem: TMenuItem;
4     i, j: integer;
5   begin
6     with MenuItem1 do {is an existing MenuItem}
7     begin
8       for i := 0 to 5 do
9       begin
10        aItem := TMenuItem.Create(MainMenu1);
11        Add(aItem);
12        aItem.Caption := IntToStr(i);
13        for j := 0 to 5 do
14        begin
15          aSubItem := TMenuItem.Create(MainMenu1);
16          aItem.Add(aSubItem);
17          aSubItem.Caption := IntToStr(j);
18          aSubItem.OnClick := MenuItemsHandler;
19        end;
20      end;
21    end;
22  end;
23  
24  procedure TForm1.MenuItemsHandler(Sender: TObject);
25  begin
26    ShowMessage((Sender as TMenuItem).Caption);
27  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC