Description:
How to Determine a dxBarButton That Calls the Dropdown Popup Menu
Answer:
In some instances, the same dxBarPopupMenu, can be used as a dropdown menu by several dxBarButtons (with ButtonStyle = bsDropDown) simultaneously. Below is a sample TdxBarPopupMenu.OnPopup event handler that allows you to determine a button that calls the menu.
Delphi// Delphi code
type
TDummyBarControl = class(TCustomdxBarControl);
procedure TYourForm.YourdxBarPopupMenuPopup(Sender: TObject);
var
BC: TCustomdxBarControl;
BI: TdxBarItem;
begin
BC := ActiveBarControl;
if (BC <> nil) and
(TmyBarControl(BC).SelectedItem <> nil) then
begin
BI := TmyBarControl(BC).SelectedItem.Item;
// do something with BI ...
end;
end;
Code// C++Builder code
void __fastcall TfrmMain::dxBarPopupMenuPopup(TObject *Sender)
{
class TmyBarControl : public TCustomdxBarControl
{
protected:
TdxBarItemControl* __fastcall GetDummySelectedItem() { return SelectedItem; };
public:
__property TdxBarItemControl* DummySelectedItem = {read=GetDummySelectedItem};
};
TCustomdxBarControl* BC = ActiveBarControl();
if ( (BC != NULL) && (((TmyBarControl*)BC)->DummySelectedItem != NULL) )
{
TdxBarItem* BI = ((TmyBarControl*)BC)->DummySelectedItem->Item;
// do something with BI ...
}
}
There is a bug in the above C++ code.
The 'SelectedItem' in line 'TdxBarItemControl* __fastcall GetDummySelectedItem() { return SelectedItem; };' is undefined. How can this be fixed? Thank you in advance for your support.
Hello Dmitri,
In latest versions of our controls you can use the SelectedLink object instead:
void __fastcall TfrmMain::dxBarPopupMenuPopup(TObject *Sender) { class TmyBarControl : public TCustomdxBarControl { protected: TdxBarItemLink* __fastcall GetDummySelectedItem() { return SelectedLink; }; public: __property TdxBarItemLink* DummySelectedItem = {read=GetDummySelectedItem}; }; TCustomdxBarControl* BC = ActiveBarControl(); if ( (BC != NULL) && (((TmyBarControl*)BC)->DummySelectedItem != NULL) ) { TdxBarItem* BI = ((TmyBarControl*)BC)->DummySelectedItem->Item; Caption = BI->CurItemLink->Caption; } }
Thank you this code works properly.
You are always welcome.