Recent

Author Topic: Popup menu: Is there a better way to build?  (Read 620 times)

QEnnay

  • Jr. Member
  • **
  • Posts: 91
Popup menu: Is there a better way to build?
« on: September 13, 2021, 07:26:42 pm »
Hi, I have 11-popup menus on a project all with at least 6-itmes each.

Is there a better way than
  double-click the menu
  double-click the first item
  add stuff to the procedure
  F12
  double-click the menu...
 repeat 67 times.

Is there some way I can manage each menu in it's entirety kinda-like the DBGrid Columns Editor?

Thanks
Linux-Mint 20.1 x64 + Cinnamon; Lenovo Flex 5 Ryzen 5 4500, 16GB memory
FPC: 3.2.0-1, Lazarus 2.0.12-0, all 64bit

mas steindorff

  • Sr. Member
  • ****
  • Posts: 468
Re: Popup menu: Is there a better way to build?
« Reply #1 on: September 13, 2021, 10:06:15 pm »
a long time ago, I built a project where I used the same popup for several components. 
in my case, the popups were nearly the same. you can use the same one for several right click parts .... just select the one you want in the object inspector while editing the component.
in code, you can figure out which component was selected by testing the parent.  it's name or simply it's TAG value.  I think I was able to get this info from the (sender) parameter.
if my memory is correct, I even was able to change what items were enabled using the popup's onshow() and marking the menu items as visible or not. 

the other way to try is to build one, place the next, go to the object inspector and copy the menu items from the built one to the new one manually
MAS
windows 7/10 - laz 2.0 / 1.2.6 general releases

QEnnay

  • Jr. Member
  • **
  • Posts: 91
Re: Popup menu: Is there a better way to build?
« Reply #2 on: September 13, 2021, 11:29:55 pm »
I built a project where I used the same popup for several components. 

Thanks, I am not a newbie to this game. :) Been programming since before there was a Delphi-I, actually Turbo-Pascal 2.something so pretty familiar with an awful lot of techniques.

Using one popup for several items just over-complicates things and can be unreadable 6-months later when the Client changes their mind. Been down that slippery path way too many times.

I can't believe we must still mess with the repeat 67 times thing.
Linux-Mint 20.1 x64 + Cinnamon; Lenovo Flex 5 Ryzen 5 4500, 16GB memory
FPC: 3.2.0-1, Lazarus 2.0.12-0, all 64bit

HeavyUser

  • Sr. Member
  • ****
  • Posts: 317
Re: Popup menu: Is there a better way to build?
« Reply #3 on: September 13, 2021, 11:30:03 pm »
Hi, I have 11-popup menus on a project all with at least 6-itmes each.

Is there a better way than
  double-click the menu
  double-click the first item
  add stuff to the procedure
  F12
  double-click the menu...
 repeat 67 times.

Is there some way I can manage each menu in it's entirety kinda-like the DBGrid Columns Editor?

Thanks
There are a couple of ways to manage this the most obvious is
1) use actions and action lists, connect the action to the menu instead of writting the code to the menu onclick event directly.
2) create a single menu click and write the code then copy paste the declaration 67 time changing the name in the editor directly and write the code and after that open the menus and manually link them to your manually created events, or write an on create event handler for the form and link them to the menus there by code.
3) after writing the first menu click handler and copying paste the 66 events manually open the form as text and add the rest of the menus with the click handlers you created.

I would choose the 1st choice use actions and actionlists to write your menu handlers and link them to menus and popupmenus, toolbars etc no need to rewrite the same code multiple times. It requires a bit of planning ahead but its far easier and faster to do in the end.

jamie

  • Hero Member
  • *****
  • Posts: 4915
Re: Popup menu: Is there a better way to build?
« Reply #4 on: September 14, 2021, 12:08:45 am »
Maybe you are using the wrong menu style..

have you looked at using a TTreeView ?
The only true wisdom is knowing you know nothing

dbannon

  • Hero Member
  • *****
  • Posts: 1586
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Popup menu: Is there a better way to build?
« Reply #5 on: September 14, 2021, 02:29:20 am »
I have one popup menu that gets used in multiple places in the app and so needs to have multiple instances of the actual menu itself. So, I create that menus in code rather than using the GUI.  That approach is probably less attractive to you as each one of your menus are different. And you would still have to write the code for each of your 67 items.

But, you only have to make those 67 items once don't you ?  Once done, its not to be done again ?  I don't really think there can be a more efficient way ....

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

 

TinyPortal © 2005-2018