Author: William Gerbert
Changing properties for all components of a certain type
Answer:
To change the font color of all the labels of a form to a certain color, call the
following procedure. In the call itself, you have to replace NewColor with an
existing color, e.g. SetLabelsFontColor(clRed) sets all the labels' font color to
red.
1 procedure TForm1.SetLabelsFontColor(NewColor: TColor);
2 var3 i: Integer;
4 begin5 for i := 0 to ComponentCount - 1 do6 if Components[i] is TLabel then7 TLabel(Components[i]).Font.Color := NewColor;
8 end;
9 10 of course, you can use this technique to change other properties of other
11 components. to change the color of all edits, the code would be:
12 13 procedure TForm1.SetEditsColor(NewColor: TColor);
14 var15 i: Integer;
16 begin17 for i := 0 to ComponentCount - 1 do18 if Components[i] is TEdit then19 TEdit(Components[i]).Color := NewColor;
20 end;