Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to change the font color of all components on a form at runtime Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Graphic
Language
Delphi 4.x
Views
98
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I would like to change the font color on all components on a form at runtime (and 
the components owned by the components etc). I devised a recursive algorithm using 
RTTI that accepts a TComponent as a parameter. It works to some extent, but I still 
have to use 'if' statements to cast the object to a particular descendant, 
resulting in about 30 lines of code to test for all of the components I use. Also, 
some objects (TColumnTitle), are not descended from TComponent, even though they 
have a font property.

Answer:

This may do the trick (with D6 and maybe D5):

1   uses
2     TypInfo;
3   
4   { ... }
5   var
6     i: integer;
7     aFont: TFont;
8   begin
9     for i := 0 to aComponent.ComponentCount - 1 do
10    begin
11      aFont := TFont(GetOrdProp(aComponent.Components[i], 'Font'));
12      if assigned(aFont) then
13        aFont.Color := clWhite;
14    end;
15  end;
16  
17  
18  //With D4:
19  
20  { ... }
21  var
22    i: integer;
23    aFont: TFont;
24    pi: PPropInfo;
25  begin
26    for i := 0 to aComponent.ComponentCount - 1 do
27    begin
28      pi := GetPropInfo(aComponent.Components[i].ClassInfo, 'Font');
29      if assigned(pi) then
30        TFont(GetOrdProp(aComponent.Components[i], pi)).Color := clWhite;
31    end;
32  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC