Page 1 of 1
Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 1:45 pm
by CAsba
Hi
Is it possible to populate the list of menu items by reference to fields or variables instead of hard-coded items ?
Re: Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 2:31 pm
by Klaus
Sorry, no idea what you mean, could you give an example?
Re: Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 2:48 pm
by CAsba
Hi Klaus,
I need to populate a menu with years, to include the current year. As this will change, instead of hardcoding 2022 as a menu item, the menu item needs to reference a field or variable referring to the current year, or, as the current year changes, code is invoked to put the current year into the list of menu items. Is it possible ?
Re: Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 2:55 pm
by dunbarx
If I understand what you mean, know that the menu items of a button are just the contents of that button. So if you:
Code: Select all
put "A" & return & "B" & return & "C" into button "yourComboBox"
Those values will appear as three choices when you click there.
Craig
Re: Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 2:56 pm
by Klaus
You can always update/fill the content of a menu button dynamically "on mousedown", if that helps.
Ah, Craig already showed you how to do this...
But still no idea what kind of menu you are trying to create "on the fly".
Could you give an example?
Re: Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 2:59 pm
by dunbarx
Klaus.
That is TWO times I beat you by just minutes in the last week!!! You now only lead by 28,435 to 2
Craig
Re: Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 3:09 pm
by Klaus
THIS MUST STOP, Craig!
Maybe I'm just getting old...
Re: Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 3:09 pm
by dunbarx
CAsba
Did you examine the handler in the "Click here" button of the stack I posted? It shows just that, loading the contents of a field into the "contents" of a button.
And as Klaus belatedly

mentioned, you can do that (very nicely, in fact) right at the menu button itself, on mouseDown. Do you see all that?
Craig
Re: Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 3:10 pm
by dunbarx
I just wanted to get to 8700.
Craig
Re: Menu items, hard-coded or references
Posted: Tue Nov 08, 2022 5:44 pm
by FourthWorld
CAsba, the others here have handled your question well. I just want to add a small but hopefully inspiring insight:
The LiveCode IDE is written in LiveCode Script. Anything you see it do -- such as providing an interface for setting the text of menu items -- is something you can do in your own apps.
So when you using the IDE to do something you'd like to do in your own script, you can look at the property name shown in the Inspector, and look that property up in the LiveCode API Dictionary.
Also, to get an empowering overview of the scope of object properties and how to use them, the User Guide included in the install (see the Help menu) is worth a skim. Just a few minutes reviewing the scope of content there will tell you where to turn to learn most aspects of LiveCode as they come up in your work.
These forums are a great resource, the people there very helpful. And when you need an answer right away, those two resources -- the Dictionary and the User Guide -- can often get you going in just minutes.
Re: Menu items, hard-coded or references
Posted: Wed Nov 09, 2022 11:12 am
by CAsba
Hi
Thanks everyone for your replies, and Craig, the code snippet you provided was spot on, it solved my prob.
Once again,
thanks to all of you.
Re: Menu items, hard-coded or references
Posted: Wed Nov 09, 2022 7:24 pm
by jacque
So when you using the IDE to do something you'd like to do in your own script, you can look at the property name shown in the Inspector, and look that property up in the LiveCode API Dictionary.
If you haven't changed it in preferences, you will see an explanation of the property instead of the LC name. To see what you should look up in the dictionary, hover the mouse over the name to see the actual property name.
Do yourself a favor and change the inspector to show the real property name. That reverses the response so that hovering shows the description.