Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


How to change a property of all components in one timeGo to manfred süsens's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
e.g. for Font, Color, and so on
Product:
Delphi 4.x (or higher)
Category:
Win API
Skill Level:
Scoring:
Last Update:
09/12/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet property, font, color
Times Scored:
2
Visits:
2325
Uploader: manfred süsens
Company: DÜRR Systems GmbH
Reference: N/A
 
Question/Problem/Abstract:
Do you know how to change a speacial property of all components own this property at one time
Answer:



The best way is to make a separate unit. On top of the unit you have to make a new type of TControl...

type
  TCheckClass = class(TControl);

Now the little procedure can call by other units...for example here we change the font name and the char set...

procedure TurnFontCharset(NewFontName:TFontName;NewCharSet:TFontCharset);
var
  n:Integer;
  procedure CheckComponent(C:TComponent);
  var
    ClassRef:TClass;
    ChangeClass:TCheckClass;
    x:Integer;
  begin
    ClassRef:=C.ClassType;
    while ClassRef<>nil do begin
      if ClassRef.ClassName='TControl' then begin
        ChangeClass:=TCheckClass(C);
        ChangeClass.Font.Name:=NewFontName;
        ChangeClass.Font.CharSet:=NewCharSet;
        break;
      end;
      ClassRef:=ClassRef.ClassParent;
    end;
    for x:=0 to C.ComponentCount-1 do CheckComponent(C.Components[x]);
  end;
begin
  for n:=0 to Form1.ComponentCount-1 do
    CheckComponent(Form1.Components[n]);
end;

What we doing:
We take the base form and looking for all child components of this form and call the sub procedure CheckComponent with the pointer to the component. In the sub procedure we first ask for the class type. Is this class type a TControl, we transfer the pointer to our on declaration. Because of the own declaration, we can get properties also if they are protected. Now we change the property and break. If the component is not a TControl, we ask for the control parent. Any time it will be a TControl or not, so we end the while circle by break or if there is no more parent. Now we look if this component has children. If happen this, we call the procedure by our self, means recursive.

That’s it.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
S. Kucherov
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)