Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programmatically find components on a Form

Posted on 2006-11-29
4
Medium Priority
?
206 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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