Solved

How to share an event handler between forms?

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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