Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add Items to Popupmenu

Posted on 1998-11-30
4
Medium Priority
?
253 Views
Last Modified: 2010-04-04
(Hello...Experts)
I have a popupmenu1 component on a form and listbox1 and one button, when i push the button i will read all the text in the listbox and add to popupmenu

I have try using TItem and nothing work, if you have a complete code , then i will be glad
Thanks!!!!
0
Comment
Question by:vis
[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
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
BigRat earned 100 total points
ID: 1348615
Each element of a popup menu is a menu item. Therefore you must take the text from each of the ListBox entries and create a menu item for it, then add that to your popup menu. I'll assume that the context for the following code is the Frame which will contain the Popup menu, because on creation of a menu item you need to specify a component (should be OK if you put it in the ButtonClick code) :-
var
    Popup    : TMenuPopup;
    NewItem : TMenuItem;

    for i:=1 to LisBox.Count do
        begin
        NewItem := TMenuItem.Create(Self);
        NewItem.Caption := ListBox.Items[i].Text;
        Popup.Add(NewItem);
        end;

OK? Reject answer if not satisfied or something is unclear.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1348616
hi vis, hi BigRat,

BigRat : Have you tested your answer?

vis: try this

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

begin

  { Clear PopupItems }

  while popupmenu1.Items.Count > 0 do
    popupmenu1.Items.Delete(0);

  { Add PopupItems }

  for i := 0 to listbox1.Items.Count - 1 do
  begin
    NewItem := TMenuItem.Create(Self);
    NewItem.Caption := listbox1.Items.Strings[i];
    popupmenu1.add(NewItem);
  end;

end;

meikl
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1348617
hi vis,

sorry, one mistake

the line
 popupmenu1.add(NewItem);

should be
 popupmenu1.items.add(NewItem);

meikl
0
 
LVL 27

Expert Comment

by:BigRat
ID: 1348618
Typical Rat! In my Popup Menu I did not extract the Texts from a ListBox but a database (context dependant popup menu) so I changed the "NewItem.Caption:=.." in a hurry. And I ALWAYS forget that these silly ListBoxes have Items which are not indexable, but one has to get Strings which are. Sorry!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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