When I make a component invisible by setting the connected TAction to invisible, the onupdate event will not trigger anymore. To recreate, do the following.
- Create a new VCL forms application
- Drop a button, a checkbox and an actionlist on the form.
- Create a new action, and connect the button to it.
Write the following code for the actions OnExecute and OnUpdate event:
procedure TForm1.Action1Execute(Sender: TObject); begin ShowMessage('Test'); end; procedure TForm1.Action1Update(Sender: TObject); begin TAction(Sender).Enabled := not CheckBox1.Checked; TAction(Sender).Visible := TAction(Sender).Enabled; end;
Run the application. The button is visible, and works properly. Check the checkbox, and the button disappears. Uncheck the checkbox. The button doesn't appear. In fact, if you put a breakpoint in Action1Update, you'll never get to it. Why is this, and how do I fix it?
No need to fix this, it works as designed. Only visible controls need to update their state, so only actions whose linked controls are visible are updated. When you hide the button there's no more reason to update the action.