Solved

Programmatically find components on a Form

Posted on 2006-11-29
4
203 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 156
Adoquery sql  left join does not work 25 99
How to create virtual printer while installing my application 5 61
update joined tables 2 55
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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