Solved

Passing procedure as parameter; Delphi 2012

Posted on 2014-10-06
4
294 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 25

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

10 Experts available now in Live!

Get 1:1 Help Now