Solved

Single Clicked Event for multiple controls (checkbox)

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month5 days, 6 hours left to enroll

635 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