Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Programmatically find components on a Form

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

885 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