Solved

Programmatically find components on a Form

Posted on 2006-11-29
4
205 Views
Last Modified: 2010-04-05
I need to be able to find (and do some processing) all (in this case) TSpeedButton of a Form.
In fact I use hundreds of forms in one large application.
The main program manages (show etc...) them.
But it should be able to do some rework on all the TSpeedButtons of these forms (to standardise them) before to show them.
So I would like to write a procedure, says StandardiseForm(F:TForm) that will do that work.
Is this possible ?
How ?
0
Comment
Question by:LeTay
[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
  • 4
4 Comments
 
LVL 28

Expert Comment

by:TName
ID: 18035734
Hi, do you mean something like this?

procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
begin
  for i:=0 to Form2.ComponentCount-1 do begin
     if Form2.Components[i] is TSpeedButton then begin
       ShowMessage(TSpeedButton(Form2.Components[i]).Caption);
       //Do whatever with the button
     end;
  end;
  //Form2.show;
end;


BTW, you can only access TSpeedButtons from within an application. They don't have window handles, so no chance accessing them via api from another application...
0
 
LVL 28

Accepted Solution

by:
TName earned 500 total points
ID: 18035775

procedure StandardiseForm(F:TForm);
var
i:Integer;
begin
   for i:=0 to F.ComponentCount-1 do begin
     if F.Components[i] is TSpeedButton then begin
       TSpeedButton(F.Components[i]).Caption:='ChangedCaption'+IntToStr(i);
       TSpeedButton(F.Components[i]).Width:=100;
       TSpeedButton(F.Components[i]).Height:=40;
     end;
  end;
  //Form2.show;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  StandardiseForm(Form2);
end;
0
 
LVL 28

Expert Comment

by:TName
ID: 18035797
Form2.Show
should read
F.Show
Don't know if you want to use Show there or not...
0
 
LVL 28

Expert Comment

by:TName
ID: 18035857
Easier to handle maybe:

procedure StandardiseForm(F:TForm);
var
i:Integer;
sb:TSpeedButton;
begin
   for i:=0 to F.ComponentCount-1 do begin
     if F.Components[i] is TSpeedButton then begin
       sb:=TSpeedButton(F.Components[i]);
       with sb do begin
         Caption:='ChangedCaption'+IntToStr(i);
         Width:=100;
         Height:=40;
         Font.Color:=clRed;
       end;
     end;
  end;
  //F.show;
end;
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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