Solved

passing a string as a component name

Posted on 2002-04-15
6
233 Views
Last Modified: 2010-04-04
hi,
I have a form with 100 checkboxes and some images on it.
they are named A1,A2,A3,A4,A5,A6 Etc..and B1,B2 ,B3

i declare a type

Type
  THackCheckbox = class(TCheckbox);

also declare THackimage = class(TImage)

for instance a string var s is  = A4 (which is name of component)

so now i could do

 THackCheckbox(A4).SetChecked(True) and it works ok

but i need to do

 THackCheckbox(s).SetChecked(True)
or
THackImage(s).MouseDown(mbleft,[],THackImage(s).left,THackImage(s).top)

which both fails miserably with some message about s is not a component name .

i tried  various "as component"  etc but no luck,is it possible to pass string as component name like this?
im sure ive seen this done before by simonet but cant find relevent q.

Regards Barry
0
Comment
Question by:inthe
  • 3
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 75 total points
ID: 6941612
what about

var
 cb : thackcheckbox;
begin
 cb := findcomponent('yourString');
 if cb <> nil then
   cb.setchecked(true);
end;

meikl ;-)
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6941617
Hi Barry,

do you mean somethong like this?

var
  C: TComponent;
begin
  C := FindComponent('CheckBox5');
  if C is TCheckBox then
    (C as TCheckBox).Checked := True;
end;

0
 
LVL 9

Expert Comment

by:ITugay
ID: 6941620
too late :-)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6941628
would i not say, igor,
even my code was from head,
and i see at your code,
that i've done a mistake
(cb must be tcomponent->i guess)

meikl ;-)
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6941646
hi meikl:-)

seems it doesn't matter in this case. Magic word was "FindComponent".

------
Igor.
0
 
LVL 17

Author Comment

by:inthe
ID: 6941682
ahhh yes findomponent will do it
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now