Solved

Addressing controls who's name is in a variable

Posted on 1998-09-12
2
129 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

17 Experts available now in Live!

Get 1:1 Help Now