Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnClick for all checkboxes 2

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have a list of checkboxes on a form:

| | Mediation held; agreement reached
| | Dispute Resolved
| | Vacate Setting
| | Set for hearing
| | Keep existing setting
| | Mediation held; No agreement


I have a private variable on the form sDocketText. I want to write a single procedure that when any checkbox is checked that writes the caption of the checked box to sDocketText.

I'm sure I need to use some form of

Code:
with Components as TCheckBox do
begin
  sDocketText := sDocketText + Component.Caption
end;

Although, now that I'm posting this, I also need to remove the text if they uncheck the box, so maybe a StringList to hold the captions?

Anyway, the bigger issue is getting the caption of the checkbox that was selected into my variable.

Any thoughts?


Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for database developers:
The Fundamentals of Relational Database Design
Understanding SQL Joins
 
Normally you will always get the Sender(=TObject) in your Events.

so this will do

Code:
...
sDocketText := TCheckbox(Sender).Caption;

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
I want to write a single procedure that when any checkbox is checked that writes the caption of the checked box to sDocketText.

select all the checkboxes.
goto the object inspector and doubleclick OnClick.
put in your code;

this 1 event now applies to all checkboxes.

Aaron
 
both of those suggestions worked great. I ended up with:
Code:
procedure TfMediationDispo.cbVacateClick(Sender: TObject);
begin
  rgVacateChoice.Enabled := cbVacate.Checked;
  rgKeepSettingChoice.Enabled :=  cbKeepSetting.Checked;
  if TCheckbox(Sender).Checked then
    sDocketList.Add(TCheckbox(Sender).Caption)
  else
    sDocketList.Delete(sDocketList.IndexOf(TCheckbox(Sender).Caption));
end;
 
slightly cleaner (more readable) version.
when I need to typecast the same object over and over, I prefer to use a more meaningful variable name instead:

Code:
procedure TfMediationDispo.cbVacateClick(Sender: TObject);

var CheckBox : TCheckBox;

begin
  CheckBox := TCheckbox(Sender);
  rgVacateChoice.Enabled := cbVacate.Checked;
  rgKeepSettingChoice.Enabled :=  cbKeepSetting.Checked;
  if CheckBox.Checked then
    sDocketList.Add(CheckBox.Caption)
  else
    sDocketList.Delete(sDocketList.IndexOf(CheckBox.Caption));
end;

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
that's slick! Thanks, always like learning something new!

Les
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top