Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Delphi (http://www.programmingforums.org/forum41.html)
-   -   Select a control by name (http://www.programmingforums.org/showthread.php?t=14739)

abajan Dec 13th, 2007 1:41 AM

Select a control by name
 
hi ;
I create some check box control in my form and i want to select it by its name
(set focus control by it name ) . woul you please help me?
abajan

Klipt Dec 13th, 2007 1:49 AM

Re: Select a control by name
 
:

CheckBox1.SetFocus;
should work; just replace 'CheckBox1' with the actual name.

abajan Dec 15th, 2007 1:40 AM

Re: Select a control by name
 
Quote:

Originally Posted by Klipt (Post 138372)
:

CheckBox1.SetFocus;
should work; just replace 'CheckBox1' with the actual name.

Thank you ;
But I want select a group of check box in loop for example
for i:=1 to 10 do
{select controls by its name}
abajan

grumpy Dec 15th, 2007 2:57 AM

Re: Select a control by name
 
You have to create an array of pointers to TCheckBox, initialise that array so the first element points to CheckBox1, the second to CheckBox2, etc etc. Then you can loop over that array.

Klipt Dec 15th, 2007 4:50 AM

Re: Select a control by name
 
Do you mean you want to tick a group of checkboxes? This is different to setting the focus on a checkbox. The focus is the dotted border that shows which control is currently responding to keyboard input, and only one control can have it at a time. So a loop which sets the focus on a group of controls will effectively only set the focus on the last one.

To tick a checkbox, you can use
:

CheckBox1.Checked = True;

When you say by name, do you know the names at design time or runtime (as strings)? You can use Grumpy's method in the former case.


All times are GMT -5. The time now is 9:26 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC