clubreseau 0 Posted September 6, 2022 How to create a popupmenu from a SQL loop with categories and sub-categories, and at the end of my loop add 2 items to all Level_Depth 3. please I am a novice would be nice if you can give me a some code how to do. Share this post Link to post
Adam 5 Posted September 6, 2022 Not the most elegant solution - but it will at least get you started: var Mi: TMenuItem; Mx: TMenuItem; begin tbl.open; tbl.First; while not tbl.eof do begin if tblIDParent.value = 2 then begin Mi := TMenuItem.create(MainMenu1); Mi.Caption := tblName.value; Mi.Tag := tblID.value; MainMenu1.Items.add(Mi); end; if tblIDParent.value = 3 then for var i := 0 to MainMenu1.items.count - 1 do if MainMenu1.items[i] is TMenuItem then if TMenuItem(MainMenu1.items[i]).tag = tblIDParent.value then begin MI := TMenuItem.create(TMenuItem(MainMenu1.items[i])); MI.Caption := tblName.value; MI.Tag := tblID.value; TMenuItem(MainMenu1.items[i]).Add(mi); Mx := TMenuItem.create(TMenuItem(MainMenu1.items[i])); Mx.Caption := 'ADD'; Mx.Tag := tblID.value; Mi.Add(mx); Mx := TMenuItem.create(TMenuItem(MainMenu1.items[i])); Mx.Caption := 'DEL'; Mx.Tag := tblID.value; Mi.Add(mx); end; tbl.next; end; end; Share this post Link to post
clubreseau 0 Posted September 6, 2022 (edited) Work perfect thank you only 1 problem on my onclick STR_PCAPTION := TMenuItem((Sender as TMenuItem).parent).caption; showmessage(STR_PCAPTION); all my category and subcategory start by &andthename ? How I can get the original name without & and how I can create subcategory to category DEL ? Edited September 6, 2022 by clubreseau Share this post Link to post
clubreseau 0 Posted September 6, 2022 (edited) 12 hours ago, Adam said: Not the most elegant solution - but it will at least get you started: var Mi: TMenuItem; Mx: TMenuItem; begin tbl.open; tbl.First; while not tbl.eof do begin if tblIDParent.value = 2 then begin Mi := TMenuItem.create(MainMenu1); Mi.Caption := tblName.value; Mi.Tag := tblID.value; MainMenu1.Items.add(Mi); end; if tblIDParent.value = 3 then for var i := 0 to MainMenu1.items.count - 1 do if MainMenu1.items[i] is TMenuItem then if TMenuItem(MainMenu1.items[i]).tag = tblIDParent.value then begin MI := TMenuItem.create(TMenuItem(MainMenu1.items[i])); MI.Caption := tblName.value; MI.Tag := tblID.value; TMenuItem(MainMenu1.items[i]).Add(mi); Mx := TMenuItem.create(TMenuItem(MainMenu1.items[i])); Mx.Caption := 'ADD'; Mx.Tag := tblID.value; Mi.Add(mx); Mx := TMenuItem.create(TMenuItem(MainMenu1.items[i])); Mx.Caption := 'DEL'; Mx.Tag := tblID.value; Mi.Add(mx); end; tbl.next; end; end; Work perfect thank you How I can create subcategory to category DEL ? Edited September 6, 2022 by clubreseau Share this post Link to post
Stano 143 Posted September 6, 2022 5 hours ago, clubreseau said: all my category and subcategory start by &andthename ? How I can get the original name without & Use the function Copy() Share this post Link to post
Lajos Juhász 293 Posted September 6, 2022 The hotkey doesn't have to be the first character. A better solution is to set the AutoHotkeys property of the popup menu to maManual. If that's not possible you can use the StripHotkey function from Vcl.Menus to remove the &. Share this post Link to post
clubreseau 0 Posted September 6, 2022 4 hours ago, Stano said: Use the function Copy() I fix it, than with AutoHotkeys property of the popup menu to maManual, Now my only problem, I want to add submenu to category DEL do you now how ? Share this post Link to post
clubreseau 0 Posted September 6, 2022 4 hours ago, Lajos Juhász said: The hotkey doesn't have to be the first character. A better solution is to set the AutoHotkeys property of the popup menu to maManual. If that's not possible you can use the StripHotkey function from Vcl.Menus to remove the &. I fix it, than with AutoHotkeys property of the popup menu to maManual, Now my only problem, I want to add submenu to category DEL do you now how ? Share this post Link to post
clubreseau 0 Posted September 6, 2022 4 hours ago, Lajos Juhász said: The hotkey doesn't have to be the first character. A better solution is to set the AutoHotkeys property of the popup menu to maManual. If that's not possible you can use the StripHotkey function from Vcl.Menus to remove the &. I fix it, than with AutoHotkeys property of the popup menu to maManual, Now my only problem, I want to add submenu to category DEL do you now how ? Share this post Link to post
clubreseau 0 Posted September 6, 2022 Someone can help me ? How I can insert some subcategory Item in Category CRÉÉ on that code ? var Mi, Mx, My: TMenuItem; tblIDParent, tblIDCat : integer; tblName :string; begin tbl.SQL.Text:='SELECT c.id_category, c.id_parent, c.level_depth, cl.name FROM category AS c LEFT JOIN category_lang AS cl ON c.id_category = cl.id_category WHERE c.id_parent >= 2 ORDER BY c.id_category'; tbl.open; tbl.First; while not tbl.eof do begin tblIDCat := tbl.Fields[0].AsInteger; tblIDParent := tbl.Fields[1].AsInteger; tblName := tbl.Fields[3].AsString; if tbl.Fields[1].AsString = '2' then begin Mi := TMenuItem.create(popupmenu1); Mi.Caption := tblName; Mi.Tag := tblIDCat; popupmenu1.Items.add(Mi); end; if tbl.Fields[2].AsString = '3' then for var i := 0 to Popupmenu1.items.count - 1 do if Popupmenu1.items[i] is TMenuItem then if TMenuItem(Popupmenu1.items[i]).tag = tblIDParent then begin MI := TMenuItem.create(TMenuItem(Popupmenu1.items[i])); MI.Caption := tblName; MI.Tag := tblIDCat; TMenuItem(Popupmenu1.items[i]).Add(mi); Mx := TMenuItem.create(TMenuItem(Popupmenu1.items[i])); Mx.Caption := 'AJOUTER'; Mx.Tag := tblIDCat; Mx.OnClick := ONCLIK_ADD; Mi.Add(mx); Mx := TMenuItem.create(TMenuItem(Popupmenu1.items[i])); Mx.Caption := 'CRÉE'; Mx.Tag := tblIDCat; Mx.OnClick := ONCLIK_CREATE; Mi.Add(mx); end; tbl.next; end; Share this post Link to post