Board index » cppbuilder » Really basic TForm and inheritance question

Really basic TForm and inheritance question


2004-01-20 11:23:12 PM
cppbuilder113
(Originally posted in borland.public.cppbuilder.language.cpp)
Suppose I have a form TfrmBase, which has some component, for example a
TTimer. It has an event handler for the OnTimer event.
I now want to design another form which inherits from TBase, say
TfrmDerived, which also needs to have an event handler for the TfrmBase
timer's OnTimer event.
In the past I've always done this by giving TfrmBase a virtual function
which is called by the OnTimer event handler, and which TDerived can
override if it wants to.
Is there a simpler way? What happens if I go into the object inspector
in TfrmDerived and change the OnTimer event to point to an event handler
in the derived class?
--
Simon Elliott
www.ctsn.co.uk/
 
 

Re:Really basic TForm and inheritance question

"Simon Elliott" < XXXX@XXXXX.COM >wrote in message
Quote
In the past I've always done this by giving TfrmBase a virtual
function which is called by the OnTimer event handler, and
which TDerived can override if it wants to.
That is the correct way to handle it. VCL events can only have one handler
assigned at a time. If the base class assignes a handler, then the derived
class cannot. And vice versa.
Gambit
 

Re:Really basic TForm and inheritance question

Remy Lebeau (TeamB) < XXXX@XXXXX.COM >writes
Quote

>In the past I've always done this by giving TfrmBase a virtual
>function which is called by the OnTimer event handler, and
>which TDerived can override if it wants to.

That is the correct way to handle it. VCL events can only have one handler
assigned at a time. If the base class assignes a handler, then the derived
class cannot. And vice versa.
Can the actual event handler be a virtual function?
--
Simon Elliott
www.ctsn.co.uk/
 

{smallsort}

Re:Really basic TForm and inheritance question

"Simon Elliott" < XXXX@XXXXX.COM >wrote in message
Quote
Can the actual event handler be a virtual function?
No, but it can call a virtual function internally.
Gambit