Solved

Dynamically referencing components through an incrementing variable

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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