Solved

Dynamically referencing components through an incrementing variable

Posted on 1998-10-23
4
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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