Solved

Single Clicked Event for multiple controls (checkbox)

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 143
PHP preg_replace code convert to Delphi 14 55
Twebbrowser add css to the header 3 25
firemonkey Android Listview Sort items 7 10
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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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