Solved

Dynamically referencing components through an incrementing variable

Posted on 1998-10-23
4
146 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

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

Title # Comments Views Activity
How to use Hashing sha1 in Delphi 2010 4 206
delphi exception 7 63
Simple Delphi Question 9 83
Downloading email attachments 2 67
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…
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…
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 …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

20 Experts available now in Live!

Get 1:1 Help Now