delphidelphi-xe6

TToolbar Button with dropdown menu greyed out


I'm having issues getting a TToolbar Button to appear "enable"

The button has an Action assigned to it - which is fire by the OnClick event

It is also setup with a Drop Down Menu, which has 2 options on it, both of which are enabled, and both of which fire off when clicked.

Despite all this the TToolbar Button steadfastly remains greyed out, but accepts the clicks.

Any suggestions?


Solution

  • You're doing things wrong. :-)

    When using actions, you don't use the button's OnClick event - you put the code in the action's OnExecute event instead (because that's what's executing - the action - and not the button). When an action is assigned to the control, the control cannot be enabled until there's a handler for the TAction.OnExecute.

    The reason for using actions is so you can put the code in a single place (events related to the action), and then every single control attached to that action uses that common code to perform the same functionality. Editing the code in that single location means all controls attached to that action see the same changes.

    If there's nothing attached to the TAction.OnExecute event, the control has nothing to do if it was selected (clicked), and so there's no reason to enable it in the first place.