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!!!!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi vis,
sorry, one mistake
the line
popupmenu1.add(NewItem);
should be
popupmenu1.items.add(NewIt em);
meikl
sorry, one mistake
the line
popupmenu1.add(NewItem);
should be
popupmenu1.items.add(NewIt
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!
BigRat : Have you tested your answer?
vis: try this
procedure TForm1.Button1Click(Sender
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