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
Solved

passing a string as a component name

Posted on 2002-04-15
6
241 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 96
Correct Component for Shopping Cart. 2 112
Delphi inherited method 6 76
Tvertscrollbox like a whatsapp layout 5 34
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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