Solved

Single Clicked Event for multiple controls (checkbox)

Posted on 1997-03-29
1
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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