Multiple inheritance

hey folks,

Here's another question on a wonderful Monday ;-))

I want to do this :
 TfrmNewCustomer = class(TForm, TGlobalNames)

Because I want TfrmNewCustomer to inherit from both TForm and from TGlobalNames...I can't. The compiler says

"[Error] usrNewCustomerDialog.pas(10): Interface type required"

Why?


Regards,

GOMF
GOMFAsked:
Who is Participating?
 
sburckConnect With a Mentor Commented:
What I do in a case like this is inherit from one of them, and add a private copy of the other, whichever I need to get to less often, and then publish the properties of the not-inherited one.

In your case:

TTfrmNewCustomer = class(TForm)
private
     fncgn : TGlobalNames;

....
published
    property foo : whatevertype read fncgn.foo write fncgn.foo;

This is as close as you get to multiple inheritance in Delphi.
0
 
King_DavidCommented:
Delphi allows single inheritance only.
Multiple inheritance is allowed with
Interfaces only.
0
 
GOMFAuthor Commented:
uhm, yick...ok then..

If I create a class that inherits from TForm and then a new class again that inherits from TGlobalNames..I get the same right ?
0
 
King_DavidCommented:
I'm sorry but No!
Try it and you'll see why not.
0
 
AttarSoftwareCommented:
There is a huge debate as to whether you need multiple inheritance, or whether the clean way is to do it as sburck states above.  Java doesn't have multiple inheritance either for the same reasons...

Without proper documentation, it is very easy to make unfollowable, and therefore unfixable code...

Tim.
0
All Courses

From novice to tech pro — start learning today.