Solved

Calling an Event Handler procedure manually..

Posted on 1997-10-21
9
138 Views
Last Modified: 2010-04-04
Hi..
  I have an event handler procedure  TForm1.BitBtn2Click(Sender: TObject); I wish to be able to call this procedure in my program without needing BitBtn2 being clicked. In other words I just want to call it like a regular procedure. Can I do this? When I try to call it by just putting 'TForm1.BitBtn2Click' in my code, I get an error saying '( required'.

Cheers
  Shawn Halfpenny
0
Comment
Question by:aztec
9 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1348540
Hi

Call it in one of your other form procedures as follows:
BitBtn2Click(nil);

Call it from a procedure that is not part of your form as follows:
Form1.BitBtn2Click(nil);

JB
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1348541
 The 'Sender' parameter can be used so that several buttons can all use the same Click Method. The Sender identifies the button which actually performed the Click.
  You are recieving the '( Required Error' because you are not supplying a Sender. In JimBobs example the Sender supplied is Nil i.e. nothing.

  Steven
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 1348542
To simulate a click press, you can just call the 'Click' method of the button i.e. BitBtn2.Click.


0
 
LVL 1

Expert Comment

by:Odie
ID: 1348543
If you are in another event you might want to pass that event's sender:

BitBtn2Click(Sender);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Accepted Solution

by:
dvaline earned 50 total points
ID: 1348544
 You have two options...

1.  Place the code in your event handler in another function and call that function from you event, and call that function from the other function.

2.  Place this code in yourfunction to call the event
  {TForm1.BitBtn2Click(BitBtn2)}
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1348545
 I think the question was soundly answered by JimBob, so I figured that he was due the points. Thats why I didn't provide an answer, just another comment, with a little extra information. It seems a little rude to jump in with an answer to a question which is simply an inferior summary of previous comments. I know where I think the points should go.

  Steven.
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1348546
I agree with StevenB, naturally...    :-)

0
 

Author Comment

by:aztec
ID: 1348547
I didn't like dvaline's answer. JimBob gave a great answer which I used. I think you should give JimBob the points as I rate his
answer Excellent!

Shawn Halfpenny
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1348548
Hmmm, but you've graded dvaline. Oh well.

Steven.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

23 Experts available now in Live!

Get 1:1 Help Now