misc Posted February 12, 2014 Posted February 12, 2014 Hi, it's me again, the guy who likes to create controls at runtime, giving you headaches... ;-) This time: TuniPopupMenu var mn: TUniMenuItem; popMenu.Items.Clear; //dont work while popMenu.Items.Count > 0 do begin //also don't work mn:= popMenu.Items[pmMastertables.Items.Count - 1]; popMenu.Items.Remove(mn); mn.free; end; for ix:= 0 to List.Count - 1 do begin mn:= TUniMenuItem.Create(self); with mn do begin Caption:= List[ix]; Hint:= 'This does something'; OnClick:= DoSomethingClick; end; popMenu.Items.Add(mn); end; Works fine to add menuitems, but the removal code at the beginning does not work in web mode. So whenever I call this routine again to populate an EMPTY menu with NEW items, the old items remain. I've tried everything... Do I need to call some refresh somewhere?! Quote
misc Posted February 13, 2014 Author Posted February 13, 2014 Hello Farshad, can you confirm if this is a bug?Even setting the menu items to invisible is ignored. popMenu.Items.Clear; //dont work while popMenu.Items.Count > 0 do begin mn:= popMenu.Items[pmMastertables.Items.Count - 1]; mn.visible:= false; //don't work popMenu.Items.Remove(mn); //don't work mn.free; end; Quote
Sherzod Posted February 13, 2014 Posted February 13, 2014 Hi Michael Schindler. Try this: ... type TxPopupMenu = class(TuniPopupMenu) end; ... procedure TMainForm.UniButton1Click(Sender: TObject); begin //Items.clear uniSession.AddJS(TxPopupMenu(uniPopupMenu1).GetMenuControl.JSName + '.items.clear();'); end; Quote
misc Posted February 13, 2014 Author Posted February 13, 2014 Did that. Now the number of menuitems is correct, but they are somewhat painted over the old ones and cannot be clicked either. So I'm actually worse off. My code: uniSession.AddJS(TxPopupMenu(pmMasterTables).GetMenuControl.JSName + '.items.clear();'); pmMastertables.Items.Clear; Result: Farshad, can you please confirm this to be a bug? How do I dynamically populate a popup menu? I have no use for a popup menu which I cannot populate dynamically from code. I need to be able to add/delete menuitems in runtime. Quote
Sherzod Posted February 14, 2014 Posted February 14, 2014 Hi Michael Schindler. You are right. Solution: add the update() after items clear: procedure TMainForm.UniButton2Click(Sender: TObject); begin //Items.clear UniSession.AddJS(TxPopupMenu(pmMasterTables).GetMenuControl.JSName + '.items.clear();'); UniSession.AddJS(TxPopupMenu(pmMasterTables).GetMenuControl.JSName + '.update();'); //pmMastertables.Items.Clear; end; Best regards. Quote
misc Posted February 14, 2014 Author Posted February 14, 2014 Perfect. it works. How do you find these kind of solutions?! Also, can you explain to me why I have to typecast like this? TxPopupMenu = class(TuniPopupMenu) uniSession.AddJS(TxPopupMenu(pmMasterTables).GetMenuControl.JSName + '.items.clear();'); Should I post this into bug reports, because obviously "pmMastertables.Items.Clear;" is not working? Quote
Sherzod Posted February 14, 2014 Posted February 14, 2014 Hi Michael Schindler. In brief I can say: 1. How do you find these kind of solutions?! - Well, on the Internet, in forums, using debuggers ... 2. TxPopupMenu(pmMasterTables).GetMenuControl.JSName - This trick provides access to protected methods of a class ... http://hallvards.blogspot.com/2004/05/hack-4-access-to-protected-methods.html 3. Should I post this into bug reports, because obviously "pmMastertables.Items.Clear;" is not working? - I do not know this is a bug or not implemented yet ... Sincerely ... Quote
Administrators Farshad Mohajeri Posted February 14, 2014 Administrators Posted February 14, 2014 Hi Michael Schindler. In brief I can say: 1. How do you find these kind of solutions?! - Well, on the Internet, in forums, using debuggers ... 2. TxPopupMenu(pmMasterTables).GetMenuControl.JSName - This trick provides access to protected methods of a class ... http://hallvards.blogspot.com/2004/05/hack-4-access-to-protected-methods.html 3. Should I post this into bug reports, because obviously "pmMastertables.Items.Clear;" is not working? - I do not know this is a bug or not implemented yet ... Sincerely ... Actually, not implemented. Quote
krueger13 Posted January 24, 2020 Posted January 24, 2020 This worked for me for a TUniMainMenu var I : Integer; begin for I := mnuTabList.Count - 1 downto 0 do // Index backwards because Count changes as you remove items. if mnuTabList.Items.Name = 'mnuStoreSettings' then // Items created dynamically. mnuTabList.Items.Free; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.