Solved

Single Clicked Event for multiple controls (checkbox)

Posted on 1997-03-29
1
173 Views
Last Modified: 2010-04-06
I'd like to set up a group of check boxes so that I can use a single clicked event and pass in an index to identify which check box is being clicked.  I tried defining my own procedure in the form definition as such:

procedure clickedcheckbox2(sender:tobject; index:integer);

and then created the procedure.  I've tried calling the procedure 2 ways:

clickedcheckbox2(self,1)

clickedcheckbox2(1)

I get the following error each time.
"clickedcheckbox2(self,1) is not a valid identifier" or "clickedcheckbox2(1) is not a valid identifier"

Can this be done and how?
0
Comment
Question by:jodyl
1 Comment
 
LVL 5

Accepted Solution

by:
julio011597 earned 100 total points
ID: 1335049
I've worked with Delphi long ago and cannot access it anymore, so by memory:

1. select one component of the 'group' -say CheckBox1-, go to the Object Inspector, double click on the onClick event: something like clickCheckBox1 should appear;
2. select one by one the others component of the 'group' and set the onClick event handler to clickCheckBox1 as well;

Now all the components share the same handler, so you need to code it accordingly. To distinguish the components you could use - say - its Name property; the code should look something like this (_by memory_):

function TForm1.clickCheckBox1(Sender: TObject);
begin
  if (Sender as TCheckBox).Name = CheckBox1.Name then
    // handle event for CheckBox1
  else if (Sender as TCheckBox).Name = CheckBox2.Name then
    // ... and so on.
end;

Note that the 'as' operator is mandatory, since you need to cast Sender, which is of the more abstract type TObject, to the right particular type.

HTH, julio
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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

15 Experts available now in Live!

Get 1:1 Help Now