Solved

Calling an Event Handler procedure manually..

Posted on 1997-10-21
9
137 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

13 Experts available now in Live!

Get 1:1 Help Now