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

x
?
Solved

Popupmenu, and selected menu

Posted on 1999-07-14
6
Medium Priority
?
456 Views
Last Modified: 2010-04-06
Hi,

I add a Complete listing of Listbox to a popupmenu.
But before I add it I strip all drive information and extensions.

So when clicking on the selected item it returns something like this;

Original Listbox : "G:\DirA\Test.mp3"
Popupmenu : "Test"

I can succesfully get the caption of it using: (Sender As TMenuItem).Caption

But since it is all stripped, I cannot use it to open the new selected file. Is there a Way to get an Integer value of the selected Menu, I didn't find any .Selected value. Is it possible??

Also, How do I clear a popupmenu? There isn't a .Clear procedure??

Thanks
Marc
0
Comment
Question by:hellfire052497
[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
6 Comments
 
LVL 7

Accepted Solution

by:
RBertora earned 200 total points
ID: 1388547
This should work:

I had the same problem as you, what I did was attach the number to the caption and then stripped it out like this:

WindowIndex := StrToInt(Copy(((Sender as TmenuItem).Caption),Length((Sender as TmenuItem).Caption),1));

But the TMenuItem has a property TAG, which you can use to store your integer value... I could have implemented it this way too...

So when you create the menu item set tag property to your integer value.

There is no clear but you can free the stuff this way:

  for LoopVariable := Menu1.Items.Count-1 downto 0 do
  begin
    Menu1.Items[LoopVariable].Free;
  end;

Cheers,
Bert.

Add a comment if you do not succeed with this please.




0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1388548
hi hellfire,

thats easy, look to my sample below

unit pop_me_u;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    PopupMenu1: TPopupMenu;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure MyClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.MyClick(Sender: TObject);
begin
  If Sender is TMenuItem then
  Begin
    //Here you get the original ListBoxEntry
    Showmessage(ListBox1.Items.Strings[TMenuItem(Sender).MenuIndex]);
    //Do Your Stuff
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Item : TMenuItem;
  I : Integer;
begin
  //Empty First
  For I := 0 to PopUpMenu1.Items.Count - 1 do
    PopUpMenu1.Items[0].Free;
  //Add New
  for i := 0 to Listbox1.Items.Count - 1 do
  begin
    Item := TMenuItem.Create(Self);
    Item.Caption := Listbox1.Items.Strings[I]; //Or Stripped Entry
    Item.OnClick := MyClick;
    PopUpMenu1.Items.Add(Item);
  end;
end;

end.

no specials must be done, RBertona ;-)

meikl
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1388549
Or if the list box is no longer available (or you don't want a dependancy), then you could set the Hint property of each menu item to the full path.
(and set ShowHint to false).

MenuItem := TMenuItem.Create(...
MenuItem.Caption := FName;
MenuItem.Hint := FullFileName;
MenuItem.ShowHint := false;

In the OnClick event,

LoadFromFile((Sender as TMenuItem).Hint);

Cheers,
Phil.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:reddarin
ID: 1388550
I am using the .hint property myself and it works like a charm.

Darin

0
 

Author Comment

by:hellfire052497
ID: 1388551
Thanks all for your help, Thanks to some of your hints I have been able to come up with this;

I := ListBox1.Items.IndexOf(ListBox1.Items.Strings[TMenuItem(Sender).MenuIndex]);

This gives me the exact Integer number of the listbox, Whether it is 5 or 100 files.

Thanks again
Marc
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1388552
hmm?

is the result by this
I:=listBox1.Items.IndexOf(ListBox1.Items.Strings[TMenuItem(Sender).MenuIndex]);
not the same as
I := TMenuItem(Sender).MenuIndex;

??

meikl

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

730 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