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 attach a popup menu to a TMenuItem 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
04-Oct-02
Category
VCL-Menu
Language
Delphi 2.x
Views
103
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How do you attach a popup menu to the TMenuItem of a main menu as a submenu at 
runtime?

Answer:

This is one way to do it. Note: The PopupMenuItems are added to an existing menu 
item of the mainmenu mnuWhatEver.

1   { ... }
2   var
3     I: integer;
4     MenuItem: TMenuItem;
5   begin
6     for I := 0 to PopupMenu1.Items.Count - 1 do
7     begin
8       with PopupMenu1.Items[I] do
9         MenuItem := NewItem(Caption, ShortCut, Checked, Enabled, OnClick, HelpContext,
10          Name);
11      mnuWhatEver.Add(MenuItem);
12    end;
13  end;


Note: when using NewItem the MenuItem has no owner you'll have to free them 
yourself when you're done with it.

You could also use:

14  MenuItem := TMenuItem.Create(Self);
15  
16  //and then copy all the properties yourself.
17  
18  MenuItem.Captions := PopupMenu1.Items[I].Caption;
19  MenuItem.OnClick := PopupMenu1.Items[I].OnClick;
20  {etc.}


			
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