Solved

How to share an event handler between forms?

Posted on 2008-10-15
3
348 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 250 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

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…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

687 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