Call inherited double click of custom Stringgrid from popup menu item

Here is one for you all.

I have a custom component based on a TStringGrid.
Obviously there is a lot more to the code below but this is all I am questioning.

   TMyGrid = class( TStringGrid)
      procedure gridDblClick( Sender: TObject);
      constructor create( pOwner: TComponent); override;


procedure TObjectAdvStringGrid.gridDblClick( Sender: TObject);

   // Do Something


constructor TObjectAdvStringGrid.create( pOwner: TComponent);
   // create based on standard
   inherited create( pOwner);
   // define defaults
   onDblClick := gridDblClick;

Now I have dropped the component onto the form, and hooked up a popupmenu to the grid.
I have a menu option I would like to just tell the grid to double click itself on its current row.
(basically I want the user to have the option of double clicking the grid themselves or to right click and choose the option from the menu)

How can I pass this through?

I tried putting another double click event on the form in the hope that the menu option could just call the double click event, which would in turn fire off the inherited, but nada.


procedure TForm1.miViewClick( sender: TObject);
   MyFormsGridDblClick( MyFormsGrid);

procedure TForm1.MyFormsGridDblClick(Sender: TObject);

What small thing am I missing?
LVL 15
Who is Participating?
2266180Connect With a Mentor Commented:
you probably don't know/understand the mechaism of events. they are not functions, so there is no inherited.

the way to go is:

procedure TForm1.miViewClick( sender: TObject);
   MyFormsGrid.gridDblClick(sender);// or self

meaning you dirrectly call (fire) the event method.

one thing to mention though: delphi doesn't support adding more events to the same event proeprty. so with your current code, the user is not allowed to create a double click event for the grid because it would overwrite your event, assigned in the constructor. so there is a design flaw in your design but ... I can't say for sure what would be the right way to go without knowing why you choosed this design.
mikelittlewoodAuthor Commented:
I understand your answer and Ill try that.

As for the second part of your answer, that is what I want to have the ability to do.
All my grids are self loading from a self creating generic object via a database dictionary, and each grid knows
a) how to load the data of different object types and build all its columns etc at runtime
b) can open another editable form based on the objects stored in the grid cells by determining the type of object

But I do want the ability to override double click events if and when required.
well... use something like:

  fuserdblclick:tdblclickevent;// whatever type is this
  procedure yourdblcick(params here);
property dblclick read fuserdblclick write fuserdblclick;

in constructor assign the existing dblclick event to yourdblclick procedure as you did.

procedure tmygrid.yourdblcick(params here);// this wil be called by the grid
  do whatever here if needed
  if assigned(fuserdblclick) then// call the user event
    fuserdblclick(pass the params)
  do whatever here if needed
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.