Title: How to access all controls in a form with RTTI
Question: Sometimes it is needed to change the looks of a group of controls
in a form.
Answer:
All visual objects of delphi are in a list - a list of components.
With the help if RTTI (runtime type information) this list can be
easely parsed and the controls can be changed.
This example shows how to change the color from all Edit and Label
controls within a form.
var comp: TComponent;
i : Integer;
begin
comp := TComponent(FindComponent('componentname'));
if comp nil then
begin
i := comp.ComponentIndex;
if Components[i] is TLabel then
TLabel(Components[i]).Font.Color := clRed;
if Components[i] is TEdit then
TEdit(Components[i]).Font.Color := clRed;
end;
end;