• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

Multiple inheritance

Is there a way to implement multiple inheritance in Delphi?
0
barzangy
Asked:
barzangy
1 Solution
 
kretzschmarCommented:
what does you mean with multiple inheritance?
0
 
raidosCommented:
The VCL does NOT support multiple inheritance, unless your working with Interfaces...

Regards
//raidos
0
 
barzangyAuthor Commented:
Well in c++ you have

class first {
  public void do1();
}

class second {
  public void do2();
}

class third : public first, public second {
}

Here class third inherits both "do1" and "do2"
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
barzangyAuthor Commented:
Raidos: Do you mean it is possible to do that using interfaces? and if yes, can you show one example?
0
 
AvonWyssCommented:
There is no multiple inheritance in Delphi (just like in Java, C# and most other OOP languages). An interface declares what functionality is suported by a class. So, for your example, you can define bot do1 and do2 as interfaces and have one class implement both interfaces. This will work and provide the wanted functionality.
0
 
lopemCommented:
barzangy,

I dont know how multiple inheritance can improve code. Can you give me an example? I know C++ has multiple inheritance. Delphi doesnt.

best regards.
Manuel Lopez (lopem)
0
 
SteveWaiteCommented:
sorry, look at com lesson 3 in that link i posted
0
 
Russell LibbySoftware Engineer, Advisory Commented:

A good example of 'mi' using COM interfaces (if you have the source) is in the OleCtnrs.pas file (TOleContainer). The TOleContainer inherits from multiple COM classes. As the others have mentioned, Delphi itself does not support 'mi using Delphi class objects.

ie: type foo1 = class(TObject, IUnknown, IEtc..) // OK
    type foo2 = class(TObject, TStringList) // NOT OK

-------
Russell
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now