Link to home
Start Free TrialLog in
Avatar of vis
vis

asked on

Add Items to Popupmenu

(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!!!!
ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kretzschmar
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
hi vis,

sorry, one mistake

the line
 popupmenu1.add(NewItem);

should be
 popupmenu1.items.add(NewItem);

meikl
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!