Recent

Author Topic: Updating mainmenu items before show  (Read 835 times)

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Updating mainmenu items before show
« on: January 23, 2021, 02:47:59 am »
I am implementing a main menu, but there are some items that must change it caption according to the value of some variables.
For example:
An item have "Start counting"
But if the app is already counting, the item must say "Stop Counting"
Is there any way to verify a variable when the  mainmenu is clicked, BEFORE it shows the items? IF so, i could so something like this:

Code: Pascal  [Select][+][-]
  1. counting : boolean;
  2. If counting then MainMenu.Items[0].Caption :='Stop counting'
  3. else MainMenu.Items[0].Caption :='Start counting';
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Updating mainmenu items before show
« Reply #1 on: January 23, 2021, 04:47:38 am »
Is there any way to verify a variable when the  mainmenu is clicked, BEFORE it shows the items?
Yes, attach a handler to the OnClick event of the (main)menu item.

It's often used for e.g. an "Edit" item where you want to (de)activate Cut/Copy/Paste/etc. depending on whether some control has a selection or the state of the clipboard.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Updating mainmenu items before show
« Reply #2 on: January 23, 2021, 07:02:58 am »
But in that case the menu item was already show.

I understood now!

Is there any way to verify a variable when the  mainmenu is clicked, BEFORE it shows the items?
Yes, attach a handler to the OnClick event of the (main)menu item.

It's often used for e.g. an "Edit" item where you want to (de)activate Cut/Copy/Paste/etc. depending on whether some control has a selection or the state of the clipboard.
« Last Edit: January 23, 2021, 07:54:41 am by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

 

TinyPortal © 2005-2018