c.Font.Color:=aNewColor;
The Font property is protected in TControl, you can't access it directly without a type-cast:
type
TControlAccess = class(TControl)
end;
procedure ChangeFontColorOf(aForm: TForm; const aControlName: string; aNewColor: TColor);
var
c: TControl;
i: Integer;
begin
if Assigned(aForm) then begin
for i:=0 to aForm.ControlCount-1 do begin
c:=aForm.Controls[i];
if c.ClassNameIs(aControlName) and IsPublishedProp(c, 'Font') then
TControlAccess(c).Font.Color:=aNewColor;
end;
end;
end;
Or, use RTTI (since you are using it anyway):
procedure ChangeFontColorOf(aForm: TForm; const aControlName: string; aNewColor: TColor);
var
c: TControl;
i: Integer;
begin
if Assigned(aForm) then begin
for i:=0 to aForm.ControlCount-1 do begin
c:=aForm.Controls[i];
if c.ClassNameIs(aControlName) and IsPublishedProp(c, 'Font') then
TFont(GetObjectProp(c, 'Font')).Color:=aNewColor;
end;
end;
end;
Either way, note that the Controls[] list only contains *immediate child controls*. If you have nested controls more than 1 level deep and want to change their colors, you will have to change the aForm parameter to a TWinControl and then drill down the parent/child hierarchy calling ChangeFontColorOf() recursively:
type
TControlAccess = class(TControl)
end;
procedure ChangeFontColorOf(aParent: TWinControl; const aControlName: string; aNewColor: TColor);
var
c: TControl;
i: Integer;
begin
if Assigned(aParent) then begin
for i:=0 to aParent.ControlCount-1 do begin
c:=aParent.Controls[i];
if c.ClassNameIs(aControlName) and IsPublishedProp(c, 'Font') then
TControlAccess(c).Font.Color:=aNewColor;
if c is TWinControl then
ChangeFontColorOf(TWinControl(c), aControlName, aNewColor);
end;
end;
end;
Otherwise, if you are just interested in controls created at design-time, use the form's Components[] list instead of the Controls[] list.