Solved

Single Clicked Event for multiple controls (checkbox)

Posted on 1997-03-29
1
166 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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