Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to share an event handler between forms?

Posted on 2008-10-15
3
Medium Priority
?
354 Views
Last Modified: 2012-05-05
I have event handler code in one form of an application that I would like to use for a component event in another form of the application.  

Each of the forms lists each other in the uses statement. but I can't see handlers from the other form in an event dropdown in the object inspector and if I type in the name of the procedure (<other_form_name>.<proc_name>) I receive an IDE error that the name is not a valid identifier.

Thanks.
0
Comment
Question by:ttheimer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 22726080
That's right. You need to make the event handler assignment at runtime.
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 1000 total points
ID: 22726090
let's say you want to use form 1's event on your form 2.
make sure
uses unit1
is in the "TOP" uses clause

and in unti1.pas, you have
uses unit2 in the bottom uses clause (after the implementation line)

It should work then

You can also assign it at runtime if you want

e.g. click on form 2, and then in the object inspector (F11) double click in it's "OnCreate" event
then put this code

procedure TForm2.FormCreate(sender: TObject);
begin
  Button1.OnClick := form1.ButtonAClick;
end;
0
 

Author Comment

by:ttheimer
ID: 22727853
TheRealLoki

I was able to define the event handlers upon execution using the second half of your answer.  

I tried setting up as described in the first half but never got it to work.  It made sense and I went back to check my setup but then ran out of time for further testing.  I will probably come back to this when more free time is available so I would be interested if this is a tested solution or a theory.

Thanks.
Tom
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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