?
Solved

How to share an event handler between forms?

Posted on 2008-10-15
3
Medium Priority
?
351 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

800 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