Solved

Call inherited double click of custom Stringgrid from popup menu item

Posted on 2007-04-04
3
575 Views
Last Modified: 2010-07-27
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.

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


implementation

procedure TObjectAdvStringGrid.gridDblClick( Sender: TObject);
begin

   // Do Something

end;

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




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.

ie.

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

procedure TForm1.MyFormsGridDblClick(Sender: TObject);
begin
   inherited;
   //
end;


What small thing am I missing?
0
Comment
Question by:mikelittlewood
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 50 total points
ID: 18850880
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);
begin
   MyFormsGrid.gridDblClick(sender);// or self
end;

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.
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 18851717
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.
0
 
LVL 28

Expert Comment

by:2266180
ID: 18852303
well... use something like:

tmygrid=class(whatever)
private
  fuserdblclick:tdblclickevent;// whatever type is this
  procedure yourdblcick(params here);
public
property dblclick read fuserdblclick write fuserdblclick;
end;

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
begin
  do whatever here if needed
  if assigned(fuserdblclick) then// call the user event
    fuserdblclick(pass the params)
  do whatever here if needed
end;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 126
Open a URL with Internet Explorer in a new tab (not a new window) 1 74
Convert a string into a TDateTime 5 52
update joined tables 2 32
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now