Wednesday, October 13, 1999, 9:43:10 PM, you wrote:
> I have a panel which has a number of controls (dbedits, dbcheckbox, etc) and
> I want to change the background colour of each control when the Insert
> button is clicked. I've tried using the Controls property like so:
> for x := 0 to Panel5.ControlCount - 1 do
> begin
> MyControl := Panel5.Controls[x];
> MyControl.Color := clRed;
> end;
> but Color is a protected property of TControl. Is there any other way of
> doing this without hard-coding each individual control. I also want to
> change the colour back when the new record is posted.
Hi Laurence,
If you have Secrets of Delphi 2 this is the first subject dealt with
in chapter 7.
If you don't, here's the code example:
procedure TForm1.ChangeColorsTo(Color: TColor);
var
I: Integer;
PropInfo: PPropInfo;
begin
{ Look up each component on the form. }
for I := 0 to ComponentCount-1 do
begin
{ Look up the run-time info for the property named Color. }
PropInfo := GetPropInfo(Components[I].ClassInfo, 'Color');
if PropInfo <> nil then
{ Set the Color property. }
SetOrdProp(Components[I], PropInfo, Color);
end;
{ Finally, change the color of the form itself. }
PropInfo := GetPropInfo(ClassInfo, 'Color');
SetOrdProp(Self, PropInfo, Color);
end;
It relies on the fact that Color is a published property and
therefore has run-time type information available.
As mentioned previously on this list, this is a book well worth owning,
although I understand that there is an updated Delphi 5 version in the
works.
Kieron.
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz