Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dynamic menu

Posted on 1997-10-14
1
Medium Priority
?
148 Views
Last Modified: 2010-04-04
Hi,

I want to add dropdown menu's in my app at runtime. This works alright.
When one of the menu-items is clicked a procedure is called. But how do I know which menu item was selected,because they all call the same proc. How do I do this? I Can't link proc's to menu-items which don't yet exist in development.
0
Comment
Question by:lizzzard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 200 total points
ID: 1347572
Lizzzard,

A very good question! Got my gears working anyway. Here's what I figured out:

First, Create the menu items at runtime
(remember that popupmenu1 is initially empty)

procedure TForm1.Button1Click(Sender: TObject);
var NewItem: TMenuItem;
      iItemCount: Integer;
BEGIN

For iItemCount := 1 to 5 DO
  Begin
    NewItem := TMenuItem.Create(PopupMenu1);
    NewItem.Caption := 'Menu Item #' + IntToStr(iItemCount);
    PopupMenu1.Items.Insert(PopupMenu1.Items.Count,                                                NewItem);
{Now we assocate a pre-definded procedure for the menu item
 All menu items are assigned the same procedure}
    NewItem.OnClick := HandleMenuClick;
end;

Cool! Now here's the pre-defined procedure to handle the menu clicks:

procedure TForm1.HandleMenuClick(Sender: TObject);
var MI: TMenuItem;
BEGIN

MI := Sender as TMenuItem;
ShowMessage(You Clicked on the menu item called ( ' +
  TM.Caption + ' )');

{Here is where you put a bunch of IF statements to handle each menu item's stuff}

END;

Hope this helps!

Pegasus
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question