Solved

Dynamically referencing components through an incrementing variable

Posted on 1998-10-23
4
145 Views
Last Modified: 2010-04-06
With one of my Delphi programs, I have many components named 'last1'...'last26' and 'new1'...'new26' all on a single form. I would like to reference each of these objects through an incrementing variable. EG: if the incrementing variable was called x, I would like to do something of the following:
  while x < 27 do
    begin
      form1.last(x).caption := ('Last', + x);
      x := x + 1;
    end;

Where x is repeatedly incremented until it reaches the value of 26 etc...
Is this possible in Delphi?
0
Comment
Question by:X_Kalibur
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 1344175
Use findcomponent like this

MyComponent : TComponent;

MyComponent := FindComponent('last'+inttostr(CompNum));

Cheers,

Raymond.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1344176
May be that should be:

    MyComponent : TComponent;

    MyComponent := FindComponent('last'+inttostr(x));

To remove any confusion with compnum...

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344177
Raymond is right....The full code..

For x := 1 to 26 do
  TButton(FindComponent('last' + IntToStr(x))).Caption := 'last' + IntToStr(x);

That's an example...

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1344178
Thanx!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

707 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