Re:Passing controls as parameters
In article <avd8bs80asge5ppobfn8oblc9cqb8sj...@4ax.com>, Ken P. <a...@123.net>
writes:
Quote
>I have a procedure to change the color and font color of controls I
>send to it. The problem is that the color properties seem to be
>protected, so I have to do something like this-
<snip>
>How can I do this without having to know what the class names are for
>each item?
>I've tried several things and I can't figure out how to do it. I
>always get "undeclared indentifier" errors.
Color and Font (and hence Font.Color) are indeed protected properties of a
TWinControl. The protected property (or method) is in the code but the compiler
does not let you access it. But the compiler allows access to a protected item
of a descendant class in the same unit as the descendant is declared in.
So declare a descendant of TWinControl. In the interface "type" clause enter :-
TColorWinControl = class(TWinControl); // I always use the reason I've declared
it in its name
Then use it as a typecast :-
procedure SetColors(Names: array of TWinControl; aColor, FontColor:
TColor);
Var
x: integer;
begin
for x := 0 to High(Names) do
if Names[x] is TWinControl then
with TColorWinControl(Names[x]) do begin
Color := aColor;
Font.Color := FontColor;
{end; with TColorWinControl(Names[x])}
{end; if Names[x] is TWinControl}
{end; for x := 0 to High(Names}
end;
Alan Lloyd
alangll...@aol.com