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;
};

class TObj2: TObj {
protected:
       int fff2;
};

class TIntf {
public:
       virtual void ppp() = 0;
};

class TObji: public TIntf,TObj {
public:
       virtual void ppp();
};

class TObj2i: public TObji,TObj2 {
public:
       virtual void ppp();
};

void TObji::ppp()
{
       printf("111 %p\n",this);
       fff = 111;
}

void TObj2i::ppp()
{
       printf("222 %p\n",this);
       fff2 = 222;
       TObji::ppp(); // like "inherited" in pascal
}

typedef list<TIntf*> myList;

int main(void)
{
       myList l;
       l.push_back(new TObji);
       l.push_back(new TObj2i);
       for (myList::iterator i = l.begin(); i != l.end(); ++i)
               (*i)->ppp(); // general interface used
}
---
TObj,TObj2 - the basic classes from foreign module
TObji,TObj2i - my additional functional implementation

But i can't invent nothing like that,
in object pascal, with him interfaces!

Some procedural hack with pointers typecasting already implemented
and works acceptable, it appear to pascal's modular quality.

Can somebody direct me to some object-style variant, maybe objfpc
relieve here (now i use delphi mode) ?

My trial object-style construction is in attachement.
It causes in me some aesthetic dissatisfaction.

Attachment: xInjectInterface.pas
Description: Binary data

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to