?
Solved

Delphi Dynamic popup menu

Posted on 2009-02-17
2
Medium Priority
?
2,283 Views
Last Modified: 2013-11-23
i'd like to know if its possible to create a popup menu (with sub menus) from and ini file or database query
0
Comment
Question by:philosullivan
1 Comment
 
LVL 14

Accepted Solution

by:
SteveBay earned 1000 total points
ID: 23666593
Yes. Not very difficult.  This code show the the basics of building a dynamic popup with a submenu.
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus;
 
type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    dxfg1: TMenuItem;
    procedure PopupMenu1Popup(Sender: TObject);
  private
    procedure MenuItemClick(Sender: TObject);
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.PopupMenu1Popup(Sender: TObject);
var Item, SubItem : TMenuItem;
begin
     PopupMenu1.Items.Clear;
     Item := TMenuItem.Create(PopupMenu1);
     Item.Caption := '&First Menu Item';
     Item.Tag := 1;
     Item.OnClick := MenuItemClick;
     PopupMenu1.Items.Add(Item);
 
     Item := TMenuItem.Create(PopupMenu1);
     Item.Caption := '&Second Menu Item';
     Item.Tag := 2;
     Item.OnClick := MenuItemClick;
     PopupMenu1.Items.Add(Item);
 
     // Submenu
     Item := TMenuItem.Create(PopupMenu1);
     Item.Caption := 'SubMenu';
     PopupMenu1.Items.Add(Item);
 
     SubItem := TMenuItem.Create(Item);
     SubItem.Caption := '&1st SubItem';
     SubItem.Tag := 31;
     SubItem.OnClick := MenuItemClick;
     Item.Add(SubItem);
 
     SubItem := TMenuItem.Create(Item);
     SubItem.Caption := '&2st SubItem';
     SubItem.Tag := 32;
     SubItem.OnClick := MenuItemClick;
     Item.Add(SubItem);
 
end;
 
procedure TForm1.MenuItemClick(Sender: TObject);
var Item : TMenuItem;
begin
     Item := TMenuItem(Sender);
     case Item.Tag of
     1 : ShowMessage('First Menu Item');
     2 : ShowMessage('Second Menu Item');
     31 : ShowMessage('1st SubMenu Item');
     32 : ShowMessage('2nd SubMenu Item');
          end;
end;
 
end.

Open in new window

0

Featured Post

Industry Leaders: 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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

862 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