?
Solved

passing a string as a component name

Posted on 2002-04-15
6
Medium Priority
?
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 300 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

801 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