Re: [fpc-pascal] Multiple inheritance is more powerful than Pascal's interfaces ?
* Matt Emson [EMAIL PROTECTED] [Fri, 25 Jan 2008 10:03:59 +]: Matt Emson translation, that is almost the same as in my attached trial: --- TObj = class protected fff: integer; end; TObj2 = class(TObj) protected fff2: integer; end; TIntf = interface procedure ppp; end; TObji = class(TObj, TIntf) public procedure ppp; virtual; // AG: virtual only for TObji's // descendants will useful end; TObj2i = class(TObj2, Tintf) //you do not need to use multiple // inheritance here!! TObj2 already // inherits from TObj // AG: but TObj2i nowise not bound // to TObji, whereas it needed to // TObji.ppp be inherited public procedure ppp; virtual; end; --- Actually that looks problematic to me: --- procedure TObj2i.ppp2; begin TObji(TObj(Self)).ppp2; // that looks too arbitrary, // have object pascal the // same natural solution as // C++'s TObji::ppp() call end; ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Multiple inheritance is more powerful than Pascal's interfaces ?
Andrey Gusev wrote: This question was posted to fpc-other, yesterday, but seems wrongful, in subject appropriation sense to that maillist. === I wish to introduce some additional (and general) functional to an existing (and foreign) freepascal's unit. I wouldn't to introduce any my own code to that foreign module, consider to development process, svn updation... With C++'s multiple inheritance quality it is easy to implement: --- #include stdio.h #include list using namespace std; class TObj { protected: int fff; }; type TObj = class protected fff: integer; end; class TObj2: TObj { protected: int fff2; }; type TObj2 = class(TObj) protected fff2: integer; end; class TIntf { public: virtual void ppp() = 0; }; type TIntf = interface procedure ppp; end; class TObji: public TIntf,TObj { public: virtual void ppp(); }; type TObji = class(TObje, TIntf) public procedure ppp; virtual; end; class TObj2i: public TObji,TObj2 { public: virtual void ppp(); }; type TObj2i = class(TObj2, Tintf) //you do not need to use multiple inheritance here!! TObj2 already inherits from TObj public procedure ppp; virtual; end; But i can't invent nothing like that, in object pascal, with him interfaces! That is a translation of what you use as an example. Alternate route is to use composition and/or aggregation. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] class constants
Regarding class constants: I missed them, too, already, although not too much. ;) Maybe you should read the documentation. Static fields are supported already for 10 years: ~/fpc/compiler cat p.pp {$mode objfpc} {$static on} type cl=class l : longint;static; end; var c1,c2 : cl; begin c1:=cl.create; c2:=cl.create; c1.l:=2; writeln(c2.l); c2.l:=3; writeln(c1.l); end. [EMAIL PROTECTED] ~/fpc/compiler ./p 2 3 [EMAIL PROTECTED] ~/fpc/compiler ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] class constants
On Friday 25 January 2008 12:30, Peter Vreman wrote: Regarding class constants: I missed them, too, already, although not too much. ;) Maybe you should read the documentation. Static fields are supported already for 10 years: ~/fpc/compiler cat p.pp {$mode objfpc} {$static on} type cl=class l : longint;static; end; var c1,c2 : cl; begin c1:=cl.create; c2:=cl.create; c1.l:=2; writeln(c2.l); c2.l:=3; writeln(c1.l); end. [EMAIL PROTECTED] ~/fpc/compiler ./p 2 3 [EMAIL PROTECTED] ~/fpc/compiler Well, once upon a time I learned that there's a difference between a variable and a constant, but ok; Borland might have changed that a bit when they introduced the notion of a typed constant. ;) More interesting here is that not only c1.L and c2.L works, but you can even access the variable without an instance at all: cl.L, just like it should. So at least there are class variables. (It might prove a bit tricky to correctly initialize them, though. AFAICS you can't give them initial values, can you? So to be on the safe side, you're probably back to doing it in the initialization section of the unit where the class is declared. This is a bit nasty.) Still, something like |cl = |class | const VersionId = '1.3.9a'; |end; seems not possible. Of course, this is easily modeled by a simple class method returning a constant value. That's why I said, I didn't miss that feature too much. Vinzent. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal