BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

virtual function not called when deriving from VCL

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Yuting Kuo
Guest





PostPosted: Thu Aug 18, 2005 6:09 pm    Post subject: virtual function not called when deriving from VCL Reply with quote



I have a virtual function which works fine here:

class I // interface
{
public:
virtual void func() = 0;
};

class A : public I
{
public:
virtual void func() { ShowMessage("A"); }
};

class B : public A
{
public:
virtual void func() { ShowMessage("B"); }
};

I* ia = new A;
I* ib = new B;

ia->func(); // "A"
ib->func(); // "B"

-----------

All is fine... the correct func() is always called. However, when class
A is a VCL Form... class B's func() is no longer called.

--------------
class A : public TCustomForm, public I
{
....

class B : public class A
{
....

I* ib = new B;
ib->func(); // "A" is displayed!!!

Strange?!
Back to top
Alan Bellingham
Guest





PostPosted: Thu Aug 18, 2005 7:18 pm    Post subject: Re: virtual function not called when deriving from VCL Reply with quote



Yuting Kuo <nospam (AT) nospam (DOT) org> wrote:

Quote:
All is fine... the correct func() is always called. However, when class
A is a VCL Form... class B's func() is no longer called.

--------------
class A : public TCustomForm, public I
{
...

class B : public class A
{
...

I* ib = new B;
ib->func(); // "A" is displayed!!!

Strange?!

Very odd. The only thing I would mention is that you have multiple
inheritance and a Delphi base class. The result is perhaps a bug in the
system due to two slightly incompatible object models.
Alan Bellingham
--
Me <url:mailto:alanb (AT) episys (DOT) com> <url:http://www.doughnut.demon.co.uk/>
ACCU - C, C++ and Java programming <url:http://accu.org/>
The 2004 Discworld Convention <url:http://dwcon.org/>

Back to top
Bruce Salzman
Guest





PostPosted: Thu Aug 18, 2005 7:51 pm    Post subject: Re: virtual function not called when deriving from VCL Reply with quote



From the online help:

"Unlike C++, the Object Pascal language does not support multiple
inheritance. Any classes that you create that have VCL or CLX
ancestors inherit this restriction. That is, you can't use multiple
base classes for a VCL-style C++ class, even if the VCL or CLX class
is not the immediate ancestor."

--
Bruce


Back to top
Alan Bellingham
Guest





PostPosted: Thu Aug 18, 2005 8:19 pm    Post subject: Re: virtual function not called when deriving from VCL Reply with quote

" Bruce Salzman" <bruce (AT) nospam (DOT) org> wrote:

Quote:
From the online help:

"Unlike C++, the Object Pascal language does not support multiple
inheritance. Any classes that you create that have VCL or CLX
ancestors inherit this restriction. That is, you can't use multiple
base classes for a VCL-style C++ class, even if the VCL or CLX class
is not the immediate ancestor."

Which means it doesn't compile.

However, in this case it does compile, presumably because the other base
class comprises only put virtual functions, and is therefore an
interface in Delphi's eyes.

(The latest version thereof having learnt something from Java and
allowing multiple inheritance so long as only one base is not an
interface.)
Alan Bellingham
--
Me <url:mailto:alanb (AT) episys (DOT) com> <url:http://www.doughnut.demon.co.uk/>
ACCU - C, C++ and Java programming <url:http://accu.org/>
The 2004 Discworld Convention <url:http://dwcon.org/>

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Aug 18, 2005 8:55 pm    Post subject: Re: virtual function not called when deriving from VCL Reply with quote


" Bruce Salzman" <bruce (AT) nospam (DOT) org> wrote


Quote:
From the online help:

That restriction was loosened in BCB6. VCL classes are allowed to use
multiple inheritance now, but only if all of the secondary classes are
abstract interfaces (all methods are abstract virtual, and there are no data
members).


Gambit



Back to top
Yuting Kuo
Guest





PostPosted: Fri Aug 19, 2005 9:21 am    Post subject: Re: virtual function not called when deriving from VCL Reply with quote

Remy Lebeau (TeamB) wrote:
Quote:
That restriction was loosened in BCB6. VCL classes are allowed to use
multiple inheritance now, but only if all of the secondary classes are
abstract interfaces (all methods are abstract virtual, and there are no data
members).

Yes - the base class is pure virtual (all member functions have "=0" and
no data members).

It compiled fine too, the problem is it doesn't call the child's version
of function as it should...

The hierarchy is :
class I (pure) <- class A <- class B

As soon as class A involves TForm (class A : public TForm, public I)
then class B's virtual functions won't work..... Maybe there is a rule
saying "you can not derive from a VCL class if it derives from more than
one class"?? Or maybe it's something to do with __closure?

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.