Access a button via a string variable

How do i access the properties of Button1 if my string variable (aString) = 'Button1'?
ex.  
var aString:String;
begin
  aString := 'Button1';
  TButton(aString).Enabled := False;
end;
jonroulAsked:
Who is Participating?
 
EpsylonConnect With a Mentor Commented:
FindComponent('Button1');
0
 
EpsylonCommented:
Actually:

var theButton: TButton;

theButton := FindComponent('Button1');

0
 
EpsylonCommented:
var b: TButton;
begin
  b := TButton(FindComponent('Button10'));
  b.caption := 'Hi';
end;

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
EpsylonCommented:
Hehe, in 4 attempts. That must be my record  :o)

and of course  b.Enabled := False;
0
 
EpsylonCommented:
This will work too. It simulates a mouse click on Button7:

TButton(FindComponent('Button7')).Click;
0
 
jonroulAuthor Commented:
Thanks for the quick response. because of such an extra 25 points have been added.


0
 
EpsylonCommented:
Thanks, that's very nice of you  :o)

Here is more interesting stuff. Maybe you can use it in the future.....
0
 
EpsylonCommented:
By the way, I guess you didn't know this:

When grading a question an A means the amount of point times 4. B is times 3, etc....

I got a B from you: 125 * 3 = 375

If you didn't raise the points with 25 and graded me an A, I would have got 400 points. A little waste.....

Cheers,

Epsylon
0
All Courses

From novice to tech pro — start learning today.