Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamically referencing components through an incrementing variable

Posted on 1998-10-23
4
Medium Priority
?
154 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 300 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Loops Section Overview
Suggested Courses

610 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