Solved

passing a string as a component name

Posted on 2002-04-15
6
234 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

15 Experts available now in Live!

Get 1:1 Help Now