Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically refernce a component

Status
Not open for further replies.

safra

Technical User
Jan 24, 2001
319
NL
Hi,

I have a form with a lot of TEdits. I would like to fill the text property of each of them through a for statement.

I can't figure out how to refer to the specific TEdit dynamically. I know I can use an array of TEdit but isn't there another solution like:

Code:
for i := 1 to 45 do
  ('P'+i as TEdit).Text := ....

But then something that does work!

Thanks,
Raoul
 
Check towerbase post in:


Why you guys are so lazy? :) :) :).

You are paying a high perfomance penalty only for not taking the work of loading an array.

My humble advise: if you are going to loop thru the TEdits a lot of times, use towerbase code to load the array in your OnCreate form and loop the array.

buho (A).
 
Thanks Buho!

Code:
for i := 1 to 45 do
  (FindComponent('P'+IntToStr(i)) as TEdit).Text := ...

have to test this though!

As for the lazy part, Yes you are right! :)

But actually I got 4 of these procedures for different component sets on the form and personally I also don't like those long lists of similar code when you can get the same result in a couple of lines.

But I will check performance, as that is more important ofcourse.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top