Reputation: 219
I have a couple of buttons on a toolbar with the Style defined as tbsDropDown and a Popup menu assigned.
I need to check if there are any records in the Database before showing the Menu. I have added btnFilter.CheckMenuDropDown; to the main part of the button so I am able to check there, but the "Down arrow" button shows the Popup. I need to intervene at that point with an Event of "BeforePopup"
Any suggestions?
Thanks
Upvotes: 0
Views: 551
Reputation: 43669
First, TToolButton.CheckMenuDropDown
is a routine which always drops down the menu, but returns False when it is not able to.
I understand that you want to disable the dropdown menu when there are no records in de dataset.
Possible solutions:
PopupMenu
property to nil) when there are no records, and vise versa. This is preferably to be done by attaching an action to the button.Interpose the TToolButton
class and override CheckMenuDown
:
type
TToolButton = class(ComCtrls.TToolButton)
private
FCanDropDown: Boolean;
public
function CheckMenuDropdown: Boolean; override;
property CanDropDown: Boolean read FCanDropDown write FCanDropDown;
end;
function TToolButton.CheckMenuDropdown: Boolean;
begin
Result := FCanDropDown and (inherited CheckMenuDropdown);
end;
But this is not a designtime solution and you have to set the CanDropDown
property at runtime accordingly.
CanDropDown
property in the above code.Upvotes: 2
Reputation: 163347
Before the menu appears, the its OnPopup
event fires. That gives you an opportunity to modify the menu's contents before you finally show it.
Upvotes: 1