Board index » delphi » casting a class

casting a class

Hello,

I have my own hint window class which has a property called
backColour (of TColor type)

In my apps creation, I use the statement
HintWindowClass := TMyHintWindow to use my hint window.

The back colour of my hint window defaults to black,
but I'd like to be able to change that at run-time.
Problem is I cannot figure out how to get to the backColour property
of my class.

I have tried
(HintWindowClass AS TMyHintWindow).backColour := clBlue
but this kind of statment is not valid. (compiler error)
My understanding of classes is getting better, but some things are
still quite vague.

Could anyone clarify how I can access the properties of my class
through the HintWindowClass. Can this be done at all?

--
Regards,
-Ryan

{ A fnord is the donut hole and also the whole donut }

 

Re:casting a class


Hi Ryan,

Quote
Ryan Nilsson-Harding wrote:
> Hello,

> I have my own hint window class which has a property called
> backColour (of TColor type)

> In my apps creation, I use the statement
> HintWindowClass := TMyHintWindow to use my hint window.

> The back colour of my hint window defaults to black,
> but I'd like to be able to change that at run-time.
> Problem is I cannot figure out how to get to the backColour property
> of my class.

The HintWindowClass is variable of a class-reference type and is not a
variable to the actual HintWindow class. The problem here is that the
TApplication class which contains the variable for the actual Hint
window class is private and does not have any protected or public
properties which exposes this variable which effectively disallows you
from accessing it in any way, shape or form without hacking into the
actual TApplication class and exposing it that way.

On a side note, there is a property Application.HintColor which does
exactly what your backColour property does.
I hope this helps.

Cheers,
Colin

Re:casting a class


Ok, I understand now, thanks. I'll use an ini file
for the properties I guess.

I was aware of the HintColor property but my hint window
has a few more enhancements that aren't available from
the Application variable.

--
Regards,
-Ryan

{ A fnord is the donut hole and also the whole donut }

Quote
> The HintWindowClass is variable of a class-reference type and is not a
> variable to the actual HintWindow class. The problem here is that the
> TApplication class which contains the variable for the actual Hint
> window class is private and does not have any protected or public
> properties which exposes this variable which effectively disallows you
> from accessing it in any way, shape or form without hacking into the
> actual TApplication class and exposing it that way.

> On a side note, there is a property Application.HintColor which does
> exactly what your backColour property does.
> I hope this helps.

> Cheers,
> Colin

Re:casting a class


Ryan,

Quote
> Ok, I understand now, thanks. I'll use an ini file
> for the properties I guess.

If you want to change the hint color dynamically, you could
use a global variable to do that. To make that a little more
decent, you could have the global variable in the implementation
section of the unit that contains the new hint class, and write
a procedure to set its value that you declare in the interface
section.

Best regards,
Frederik.

Other Threads