I have a class, DrumButton, that derives from TextButton. This class therefore can be ‘listened to’ like any other button that inherits from the Button superclass. I’d like to use the onClicked() method with DrumButton.
I add the MainComponent as a listener to each DrumButton as well as some other initial setup as follows…
auto count = buttonCollection.myButtons.size();
for (DrumButton* button : buttonCollection.myButtons)
{
addAndMakeVisible(button);
button->setBounds(window.removeFromLeft(window.getWidth() / count));
button->addListener(this);
count--;
}
Then override the virtual buttonClicked() method of the Listener…
void MainComponent::buttonClicked(Button* button)
{
//I would like to access a property of DrumButton here to assign a vlaue to '???'
button->onClick = [this]()
{
const auto message = generateNoteMessage(???);
auto timeCode = calculateTimeCode(message.getTimeStamp());
addMidiMessageToList(message, timeCode);
};
}
This above works great - but I would like to access some property of DrumButton inside the buttonClicked method, which is not possible because it takes a Button as it’s argument.
Is there anyway to allow buttonClicked to accept a class derived from Button? Or is there another way to accomplish this?

plus a little extra too.