Alternatively, if you make the declaration in the same unit in which
you're doing the cast, then

type TControlHack = class(TControl);

is sufficient.  All protected properties of TControl are now accessible
when you cast.

> for X = 0 to ControlCount do
>  TcontrolHack( Controls[x]).Color := clRed;

Will work.

Cheers,

Carl Reynolds                      Ph: +64-9-4154790
CJN Technologies Ltd.             Fax: +64-9-4154791
[EMAIL PROTECTED]                DDI: +64-9-4154795
PO Box 302-278, North Harbour, Auckland, New Zealand
12 Piermark Drive, North Harbour Estate, Auckland, NZ
Visit our website at http://www.cjntech.co.nz/

> -----Original Message-----
> From: Myles Penlington [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, October 14, 1999 9:10 AM
> To:   Multiple recipients of list delphi
> Subject:      RE: [DUG]:  Changing control style
> 
> Do it this way - I use this method frequently - usually need it for
> drag and
> drop as I need to access the
> dragcursor property of TControl (it's protected also).
> 
> As all are descendants of TControl, you just need access to the
> protected
> color property.
> You can do this with any property that is declared in TControl - or
> TWinControl if the control is a descendant of TWinControl.
> 
> TCOntrolHack = class(TControl)
> public
>   property Color;
> end;
>  for X = 0 to ControlCount do
>   TcontrolHack( Controls[x]).Color := clRed;
> 
> 
> 
> > -----Original Message-----
> > From:       Laurence Bevan [SMTP:[EMAIL PROTECTED]]
> > Sent:       Wednesday, 13 October 1999 21:43
> > To: Multiple recipients of list delphi
> > Subject:    [DUG]:  Changing control style
> > 
> > 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.
> > 
> > Laurence Bevan
> > Master Business Systems Ltd
> > 
> > 
> >
> ----------------------------------------------------------------------
> ----
> > -
> >     New Zealand Delphi Users group - Delphi List -
> [EMAIL PROTECTED]
> >                   Website: http://www.delphi.org.nz
> ----------------------------------------------------------------------
> -----
>     New Zealand Delphi Users group - Delphi List -
> [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz

application/ms-tnef

Reply via email to