Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-11

Problem with multiple inheritance

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

I was trying to split the o-o wrappers around Qt procedural wrappers in 2 parts. One that depends on Lazarus and another that can be used with only Free Pascal.

So I have some classes like this:

TQtWidget = class(TObject)

TQtFrame = class(TQtWidget)

Both classes contain mixed code for accessing Qt functions and procedures specific for Lazarus, like Event loops, methods that receive lazarus classes, methods to receive event signals, etc.

So I would now have, after splitting:

For pure Qt:

TQtWidget = class(TObject)

TQtFrame = class(TQtWidget)

And for laz parts:

TLazQtWidget = class(TObject)

TLazQtFrame = class(TLazQtWidget, TQtFrame)

The problem is that on TLazQtFrame I would like to inherit all functions from a normal TQtFrame, but I would also like to inherit all functions from TLazQtWidget.

How can I work around this? I mean, how can I redesign my idea to make it work with FP?

Note that Qt requires that all methods to receive events, and signals be from objects (I cannot use a procedure to receive events).

thanks,

Felipe Monteiro de Carvalho

Reply by email

Marc Weustink
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 39 lines
Hello, I was trying to split the o-o wrappers around Qt procedural wrappers in 2 parts. One that depends on Lazarus and another that can be used with only Free Pascal. So I have some classes like this: TQtWidget = class(TObject) TQtFrame = class(TQtWidget) Both classes contain mixed code for accessing Qt functions and procedures specific for Lazarus, like Event loops, methods that receive lazarus classes, methods to receive event signals, etc. So I would now have, after splitting: For pure Qt: TQtWidget = class(TObject) TQtFrame = class(TQtWidget) And for laz parts: TLazQtWidget = class(TObject) TLazQtFrame = class(TLazQtWidget, TQtFrame) The problem is that on TLazQtFrame I would like to inherit all functions from a normal TQtFrame, but I would also like to inherit all functions from TLazQtWidget. How can I work around this? I mean, how can I redesign my idea to make it work with FP? Note that Qt requires that all methods to receive events, and signals be from objects (I cannot use a procedure to receive events).

Use the TQt class tree as a private for the TQtWS class tree. The Qt tree doesn't have to match 1:1 to the WS tree.

(exactly this problem made me inplement the virtusl classes :)

Marc

Reply by email

Matt Emson
to Felipe Monteiro de Carvalho: I was trying to split the o-o wrappers around Qt procedural wrappers in 2 parts. One that…
Show quoted text 5 lines
How can I work around this? I mean, how can I redesign my idea to make it work with FP? Note that Qt requires that all methods to receive events, and signals be from objects (I cannot use a procedure to receive events).

In Delphi, I'd do it through interfaces. Delphi has this neat little trick that lets you have a property that implements an interface. Assuming FPC supports that, if you need to refer to the class that owns the property, you simply add a property of the correct interface type that the owner implements and then set it on creation. Having said all that, if you go OTT with this, there are a number of bugs I found (at least in Delphi 5) that make A/V's happen quite frequently.

Okay, if that option is not available, use a design pattern, like the Adaptor or Mediator , or cheat. I wrote a basic wrapper for the Be API in Free Pascal (not the one that you may have heard of - that was occo, mine was more like the Kylix Qt wrappers.) But what I found was that I needed to do things that the BeAPI didn't support. So I wrote a glue library in C++ that took each control and added the features I wanted at the level I needed them in C++. I then created an "abstract" class tree to represent each Pascal class, with lots of protected members. I then promoted the methods and properties I needed as and when I needed them. This strikes me as what you need.

Alternatively, look at the way occo did it for BeOS. http://www.sf.net/projects/befpc . An older version of my (now lost) code is there too.

Oh, whilst were speaking, please stop mentioning Lazarus every time people mention Kylix on the B.P.D.Non-tech news group. It's tiresome. All you'll end up doing is making people realize that Kylix did more than Lazarus does at the moment in Kylix 1. You're turning more people off than on IMHO.

Reply by email

Felipe Monteiro de Carvalho
to Matt Emson
Matt Emson wrote
Oh, whilst were speaking, ....

In the future, make this kind of comments in private, not in the middle of a technical discussion. This has no place on this thread.

Reply by email

Matt Emson
to Felipe Monteiro de Carvalho
In the future, make this kind of comments in private,

Would you listen any more gracefully?

not in the middle of a technical discussion.

It was related to the discussion. It was also a small proportion of the rest of the email. 24 lines, only 4 related to this outburst. You are overreacting.

This has no place on this thread.

Debatebale.

Please refrain from ordering me to do *anything* and then maybe we can all speak like adults. I at least had the courtesy to say "please" and certainly didn't assume any form of authority over you.

Reply by email