[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 144
  • Last Modified:

Calling an Event Handler procedure manually..

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
aztec
Asked:
aztec
1 Solution
 
JimBob091197Commented:
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
 
StevenBCommented:
 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
 
andrewjbCommented:
To simulate a click press, you can just call the 'Click' method of the button i.e. BitBtn2.Click.


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
OdieCommented:
If you are in another event you might want to pass that event's sender:

BitBtn2Click(Sender);
0
 
dvalineCommented:
 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
 
StevenBCommented:
 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
 
JimBob091197Commented:
I agree with StevenB, naturally...    :-)

0
 
aztecAuthor Commented:
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
 
StevenBCommented:
Hmmm, but you've graded dvaline. Oh well.

Steven.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now