How to override on click event of custom Firemonkey control


I am attempting to create a custom Firemonkey control which inheirts from the TListView control. I want to add some functionality to the control which is automatically executed when a user clicks on the control. Therefore, my goal is NOT to specify an OnItemClick method on my control’s form, but rather add functionality directly into the control itself.

I am struggling to comprehend what I need to do in order to tap into the on click handler for TListView. In my head, I imagine my solution would look something similar to this pseudo code:

//somewhere in the base TListView code
void __fastcall TListView::ClickHandler()
//logic for handling a click on the list view

//somewhere in my custom list view control
void __fastcall TMyListView::ClickHandler()
TListView::ClickHandler(); //call base click handler so all the normal stuff happens

//my additional logic goes here

However, I cant seem to find anything in the documentation about what method I should attempt to override, or how I should be going about this at all.

I did find this information about calling the ‘Click-event’ handler. I set up a simple example like so:

void __fastcall TFmListView::Click()
ShowMessage(“This is the control’s click”);

This works fine, however according to the documentation:

If the user has assigned a handler to a control’s OnClick event, clicking the control results in that method being called.

Therefore, any additional logic I placed in the Click() method of the control would be lost if one of the control’s on click event properties was set.

What is the proper way to go about extending the functionality of what happens when a custom control is clicked?

Comments are closed.