Solved

Passing procedure as parameter; Delphi 2012

Posted on 2014-10-06
4
309 Views
Last Modified: 2014-10-08
In a Delphi 2010 library, I need to dynamically create a popupmenu (this part is fine), associate it with a control (also fine I think), and associate the created menu items with an OnClickEvent back in the calling program (this is the problem). I have a procedure that simplified is like this:
TMymenu.Create(aControl:TControl; onClickEvent:TProcedure;...)

Open in new window

This creates the menu and associates the procedure with the OnClick events for the created menu items. I try to call this with something like:
MyMenu.create(anEdit, EditOnClickEvent...);

Open in new window

(MyMenu is an instance of TMyMenu, and object I created with various stuff needed for the menu to work.) When I compile, I get "Incompatible types: 'regular procedure and method pointer'". Need guidance on passing the procedure. Need guidance on how to correctly pass the procedure. Thanks.
0
Comment
Question by:EricTaylor
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 500 total points
ID: 40365474
Try changing to:

TMymenu.Create(aControl:TControl; onClickEvent:TNotifyEvent;...)

Open in new window


TNotifyEvent is defined in Classes, so you might need to add that to your uses, it's probably already there though.
0
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 40365482
is your EditOnclick... procedure part of a main class? If not - should be.
0
 

Author Comment

by:EricTaylor
ID: 40369028
Sinisa, the procedure is correctly defined as part of a main class.
0
 

Author Closing Comment

by:EricTaylor
ID: 40369029
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug For loops? 3 57
Error E2158 compiling with Delphi XE10 Seattle 2 115
can't find the executable in Simulator 1 101
SUM 2 INTEGER ARRAYS INTO 1 10 108
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

830 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