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

x
?
Solved

Sub-popupmenu of a popupmenu...

Posted on 2014-01-18
3
Medium Priority
?
320 Views
Last Modified: 2014-01-19
Hi Experts... I have a popupmenu with several items dynamically populated in my app. I would like to have it so that when a user clicks on any of these items in the popupmenu, another very small popupmenu will appear showing always the same two entries (For example: Numeric, and Text). SO in other words, the user click an item from the first popup, then he needs to specify whether the item he clicked is a Numeric or Text value, so he does another selection accordingly from the 2nd popup that immediately appears. How to do this?

Thanks!
    Shawn
0
Comment
Question by:shawn857
[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
  • 2
3 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 39791180
Use two PopupMenus. The first PopupMenu Items' OnClick fire the second one:

procedure TForm1.MenuItem1Click(Sender: TObject);
begin
  PopupMenu2.Popup(PopupMenu1.PopupPoint.X, PopupMenu1.PopupPoint.Y+24);  //Show the other menu a little bit beneath the first menu position
end;

Open in new window


Or use SubMenu.
0
 
LVL 24

Accepted Solution

by:
jimyX earned 2000 total points
ID: 39791262
Here is a complete example (Create new application, drop a listbox, doubleClick on your form to generate FormOnCreate, and then replace your unit with the following code):
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    PopMenu1: TPopupMenu;
    PopMenu2: TPopupMenu;

    // MenueItems OnClick Events
    procedure Show11Click(Sender: TObject);
    procedure Show21Click(Sender: TObject);
    procedure Numeric1Click(Sender: TObject);
    procedure Text1Click(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Show11Click(Sender: TObject);
begin
  PopMenu2.Tag := 1;
  PopMenu2.Popup(PopMenu1.PopupPoint.X, PopMenu1.PopupPoint.Y+24);
end;

procedure TForm1.Show21Click(Sender: TObject);
begin
  PopMenu2.Tag := 2;
  PopMenu2.Popup(PopMenu1.PopupPoint.X, PopMenu1.PopupPoint.Y+24);
end;

procedure TForm1.Numeric1Click(Sender: TObject);
begin
  if PopMenu2.Tag = 1 then  // to distinguish between which MenuItem is calling the second menu, just assign a flag or use the tag property
    begin
      Showmessage(IntToStr(3 + StrToInt(ListBox1.Items[ListBox1.ItemIndex])));
    end;

  if PopMenu2.Tag = 2 then
    begin
      Showmessage(IntToStr(4 + StrToInt(ListBox1.Items[ListBox1.ItemIndex])));
    end;
end;

procedure TForm1.Text1Click(Sender: TObject);
begin
  if PopMenu2.Tag = 1 then
    begin
      Showmessage(ListBox1.Items[ListBox1.ItemIndex]);
    end;

  if PopMenu2.Tag = 2 then
    begin
      Showmessage(ListBox1.Items[ListBox1.ItemIndex]);
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Show11: TMenuItem;
  Show21: TMenuItem;
  Numeric1: TMenuItem;
  Text1: TMenuItem;
begin
  PopMenu1 := TPopupMenu.Create(Self);
  PopMenu2 := TPopupMenu.Create(Self);

  Show11 := TMenuItem.Create(PopMenu1);
  Show21 := TMenuItem.Create(PopMenu1);
  Show11.Caption := 'Show1';
  Show21.Caption := 'Show2';
  Show11.OnClick := Show11Click;
  Show21.OnClick := Show21Click;
  PopMenu1.Items.Add(Show11);
  PopMenu1.Items.Add(Show21);

  Numeric1 := TMenuItem.Create(PopMenu2);
  Text1 := TMenuItem.Create(PopMenu2);
  Numeric1.Caption := 'Numeric';
  Text1.Caption := 'Text';
  Numeric1.OnClick := Numeric1Click;
  Text1.OnClick := Text1Click;
  PopMenu2.Items.Add(Numeric1);
  PopMenu2.Items.Add(Text1);

  ListBox1.PopupMenu := PopMenu1;
  ListBox1.Items.Add('Item 1 Text');
  ListBox1.Items.Add('4');
  ListBox1.Items.Add('Item 2 Text');
  ListBox1.Items.Add('7');
  ListBox1.Items.Add('Item 3 Text');
end;

end.

Open in new window


It's just an idea, it could be improved.
0
 

Author Closing Comment

by:shawn857
ID: 39793430
Fantastic, thank you Jimy!

Ciao
  Shawn
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 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