Board index » delphi » [Fwd: Accessing other properties through Controls property]

[Fwd: Accessing other properties through Controls property]

[ Attached Message ]

From: Moeen Chowdhary <chowd...@mcmaster.ca>
To:
Date: Thu, 29 Jan 1998 22:15:31 -0500
Local: Thurs, Jan 29 1998 10:15 pm
Subject: Accessing other properties through Controls property
Hi,
        I have a problem I need some help with.

        In a Delphi program I am using the Controls property of
TGroupBox to access properties of child controls.

    I am using the following code

    ButtonGroup.Controls[index].Enabled := True;

    This code works fine however, when I try to use something like the
following:

    ButtonGroup.Controls[index].Glyph.LoadFromFile('bitmap.bmp');

    I get an error message using the above code.  (Undefined property
'Glyph')
    The ButtonGroup is a control of type TGroupBox, and the Controls
property is
    referencing a button of type TBitBtn.  (Im trying to load pictures
into several buttons at
    once)

    Does anyone know what the problem is here????  And, how can I get
around this problem????

    Any help would be appreciated.  You may send replies via email to
chowd...@mcmaster.ca

Thanks,

Moeen.

 

Re:[Fwd: Accessing other properties through Controls property]


In article <34D14E75.7B82D...@mcmaster.ca>, Moeen Chowdhary

Quote
<chowd...@mcmaster.ca> writes:
>        In a Delphi program I am using the Controls property of
>TGroupBox to access properties of child controls.

>    I am using the following code

>    ButtonGroup.Controls[index].Enabled := True;

>    This code works fine however, when I try to use something like the
>following:

>    ButtonGroup.Controls[index].Glyph.LoadFromFile('bitmap.bmp');
>    I get an error message using the above code.  (Undefined property
>'Glyph')
>    The ButtonGroup is a control of type TGroupBox, and the Controls
>property is  referencing a button of type TBitBtn.

.Controls[index] returns an object of type TControl which has an Enabled
property, but the compiler checks and it does not have a Glyph property.

However _you_ know that the actual Controls[i] in the ButtonGroup is of type
TBitBtn (derived from TControl) and does have a Glyph property. So you can tell
the compiler it's OK by typecasting it as a TBitBtn.

  TBitBtn(ButtonGroup.Controls[index]).Glyph.LoadFromFile('bitmap.bmp');

 But if it happens to be a type which does not have a glyph, you will get an
exception at run-time. To protect against this, code :-

with ButtonGroup do
 if (Controls[index] is TBitBtn)then
  TBitBtn(Controls[index]).Glyph.LoadFromFile('bitmap.bmp');

Handling Components[index] is similar.

Alan Lloyd
alangll...@aol.com

Re:[Fwd: Accessing other properties through Controls property]


Quote
Moeen Chowdhary wrote:

>                                                   ------------------------------------------------------------------------

> Subject: Accessing other properties through Controls property
> Date: Thu, 29 Jan 1998 22:15:31 -0500
> From: Moeen Chowdhary <chowd...@mcmaster.ca>
> Organization: McMaster University, Hamilton, Ontario, Canada (NewServer)
> Newsgroups: comp.lang.pascal.delphi.components.misc

> Hi,
>         I have a problem I need some help with.

>         In a Delphi program I am using the Controls property of
> TGroupBox to access properties of child controls.

>     I am using the following code

>     ButtonGroup.Controls[index].Enabled := True;

>     This code works fine however, when I try to use something like the
> following:

>     ButtonGroup.Controls[index].Glyph.LoadFromFile('bitmap.bmp');

>     I get an error message using the above code.  (Undefined property
> 'Glyph')

Just a suggestion, but you might try,

 ButtonGroup.Controls[index].Picture.LoadFromFile('bitmap.bmp');
or
 ButtonGroup.Controls[index].Picture.Bitmap :=
LoadFromFile('bitmap.bmp');

Hope that helps!

Rkr

--
                   \|||/
                   /'^'\
                  ( 0 0 )
--------------oOOO--(_)--OOOo--------------
. Reid Roman                              .
. Delphi Programmer / Analyst             .
. TVisualBasic:=class(None);              .
. May the Source be With You              .
-------------------------------------------
. Auto-By-Tel (http://www.autobytel.com)  .
. Irvine, CA U.S.A                        .
. E-Mail : rkroman (at) pacbell (dot) net .
. or reidr (at) autobytel (dot) com       .
-------------------------------------------

Re:[Fwd: Accessing other properties through Controls property]


Quote
Moeen Chowdhary wrote:

>     ---------------------------------------------------------------

> Subject: Accessing other properties through Controls property
> Date: Thu, 29 Jan 1998 22:15:31 -0500
> From: Moeen Chowdhary <chowd...@mcmaster.ca>
> Organization: McMaster University, Hamilton, Ontario, Canada (NewServer)
> Newsgroups: comp.lang.pascal.delphi.components.misc

> Hi,
>         I have a problem I need some help with.

>         In a Delphi program I am using the Controls property of
> TGroupBox to access properties of child controls.

>     I am using the following code

>     ButtonGroup.Controls[index].Enabled := True;

>     This code works fine however, when I try to use something like the
> following:

>     ButtonGroup.Controls[index].Glyph.LoadFromFile('bitmap.bmp');

>     I get an error message using the above code.  (Undefined property
> 'Glyph')
>     The ButtonGroup is a control of type TGroupBox, and the Controls
> property is
>     referencing a button of type TBitBtn.  (Im trying to load pictures
> into several buttons at
>     once)

>     Does anyone know what the problem is here????  And, how can I get
> around this problem????

>     Any help would be appreciated.  You may send replies via email to
> chowd...@mcmaster.ca

> Thanks,

> Moeen.

How about Typecasting???????? (Just a suggestion)

Other Threads