Delphi source code

Changing the properties of all components of a certain type


To change the font color of all the labels of a form to the same color, call the following procedure. In the call, you have to replace NewColor with an existing color, e.g. SetLabelsFontColor(clRed) sets all the labels' font color to red:

procedure TForm1.SetLabelsFontColor(NewColor: TColor);
var
  i: Integer;
begin
  for i := 0 to ComponentCount - 1 do
    if Components[i] is TLabel then
      TLabel(Components[i]).Font.Color := NewColor;
end;

Of course, you can use this technique to change other properties of other components. To change the color of all the edit components, use the following code:

procedure TForm1.SetEditsColor(NewColor: TColor);
var
  i: Integer;
begin
  for i := 0 to ComponentCount - 1 do
    if Components[i] is TEdit then
      TEdit(Components[i]).Color := NewColor;
end;

TOP   DelphiLand Club Membership  DC Library  Forum  Forum Archives
Crash Course Delphi    Tips  Source Code  Downloads  Links

© Copyright 1999-2018 
DelphiLand