Solved

Calling an Event Handler procedure manually..

Posted on 1997-10-21
9
139 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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
 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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