Enabling/disabling program functions lazarus / 21-General ---------------------------------------------------------------------- dietmar · 2021-09-27 13:30 Hi, I have an application where I do want to enable/disable several functions (e.g. main menu items and so on) based on the state of the program (which can get quite complicated). So an easy way could be to setup a timer which checks all circumstances twice a second or so which then enables/disables the functions - but that seems like quite a sick method for me. Is there a better way to achieve that? Thx, --Dietmar ---------------------------------------------------------------------- glorfin · 2021-09-27 13:38 Hi! If this is GUI application made with Lazarus, you can use Application.OnIdle method. Consider also using TAction and its successors, it has a special method OnUpdate which is called from Application.Idle. Additional advantage is that you can bind same Action to menu items, hot keys and speedbutttons, so, their state is updated in a coordinated way. ---------------------------------------------------------------------- MarkMLl · 2021-09-27 13:42 If this is in the context of Lazarus/LCL, you can normally hook an event before a menu is displayed which allows you to enable/disable/hide as appropriate. If you need even more control, you can at a pinch simulate a "main menu" using dropdowns. That can be handy if you also want e.g. a progress bar, or if you want to e.g. offset the help menu to the extreme RH end. MarkMLl ---------------------------------------------------------------------- Zvoni · 2021-09-27 13:42 This sounds a lot like "Validation during input/run" Define the go/no go criterias for each item that has to be enabled/disabled, and then use the proper Event-Handlers of the controls which should control the behavior (Not sure if i've explained it well). a "classic" is "Disable Login-Button as long as username and password are NOT provided" In that case you would check the OnChange-Event of both TEdits checking if the TEdit is empty or not ---------------------------------------------------------------------- Bart · 2021-09-27 15:51 Quote from: glorfin on September 27, 2021, 03:38:34 pmHi! If this is GUI application made with Lazarus, you can use Application.OnIdle method. That will cause a lot of flickering weh you disable/enable GUI components like a menu, better use the suggestion of MarkMLl for menu's. Bart ---------------------------------------------------------------------- glorfin · 2021-09-28 14:12 Quote from: Bart on September 27, 2021, 05:51:20 pmQuote from: glorfin on September 27, 2021, 03:38:34 pmHi! If this is GUI application made with Lazarus, you can use Application.OnIdle method. That will cause a lot of flickering weh you disable/enable GUI components like a menu, better use the suggestion of MarkMLl for menu's. Bart Why? It's a standard solution. Well, usually you do not even need to do it directly. Just define Action.OnUpdate, and it is automatically called from OnIdle. But anyway, why would you expect flickering? ---------------------------------------------------------------------- Bart · 2021-09-28 16:31 I don't expect that, I saw it. I used OnIdle to update my menu Items, and that caused a visual mess. Now I update my menuItems upon opening. Bart ---------------------------------------------------------------------- glorfin · 2021-09-29 16:54 Maybe depends on use of Invalidate/Repain etc. As I have said, I am using TAction.Enabled, and when its status is changed, LCL itself redraws all controls, linked to this Action, from Application.Idle, and there is no flickering.