Solved

Addressing controls who's name is in a variable

Posted on 1998-09-12
2
130 Views
Last Modified: 2010-04-06
How can I address the properties of a control whose name I have in a variable?

I have tried something like this:-

TControl(ControlName).Property := xxxx;

While compiles happily I get an address error on run. I realsie I am apparently typecasting the ControlName variable to TControl and this is probably the cause of the error but I can't see the way to solve the problem.

Thanks

Chris
0
Comment
Question by:ChrisBerry
2 Comments
 
LVL 2

Accepted Solution

by:
rene100 earned 50 total points
ID: 1339500
try the FindComponent Method.
Example for a form with a TLabel named label1 on it:

procedure TForm1.Button1Click(Sender: TObject);
var
a: string;
b: TComponent;
begin
a:='label1';
b:=Findcomponent('label1');
(b as Tlabel).caption:='NewText';
end;

regards
rene
0
 

Author Comment

by:ChrisBerry
ID: 1339501
Thank you, I had implemented a find component using the component list of the form but I thought there must be a better way.


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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

947 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

23 Experts available now in Live!

Get 1:1 Help Now