Jan,

          my approach is more or less the same of yours.

Every Pascal class implements  (will implement) all the methods of the wrapped class plus one interface containing all the virtual function. A pointer to this interface is passed to the C++ class that will used it to forward the virtual functions to  the methods of the interface.

Eg.

C++

       class A
        {

          public:

              void Method1() ...;
              virtual void Method2();


        };

Pascal

      IA_VirtualMethods = interface

            procedure Method2();

      end;

      TA = class(TSwigObject, IA_VirtualMethods)

       protected

            procedure DoMethod2(); implements   IA_VirtualMethods.DoMethod2();


       public

            constructor Create();
            procedure DoMethod1();
            procedure DoMethod2();

      end;

constructor TA.Create();
begin
   FSwigObj := new_A();
   FSwigObj.SetVirtualMethodos( Self As IA_VirtualMethods );
end;
  

SWIG:

class IA_VirtualMethods {

public:

        virtual void Method2() = 0;
  

};

class SWIGWrappedA : public A

{

private:

    IA_VirtualMethods * v;
 public
    void SetVirtualMethods (IA_VirtualMethods *);

     void Method2() { v->void Method2(); }


}


More or less this is the Idea.


This should be the same in you case. The Pascal As operator performs a QueryInterface on the target Object.

Delphi Pascal interfaces are fully COM compliant infterfaces

Stefano


Stefano,

I have not started implementing directors yet, but I've had some thoughts about it. I also think that interfaces are the way to go. The objects created using the COM wrapper implement 2 interfaces (in addition to IUnknown and IDispatch) - one is the interface corresponding to the C++ object (containing all its member functions and variables) and the other one, currently called SWIGWrappedObject, allows to get the pointer to the underlying C++ object. So for director support I plan to check whether an object passed as argument implements SWIGWrappedObject - if yes then I can just call the underlying object; otherwise some form of directors will be needed. I don't know if a similar approach will work for Delphi - I have very limited knowledge about it.

I will be away from home for a few days, so please cc my e-mail address (jezabek@poczta.onet.pl) - it is easier for me to check my mail than the newsgroup.


Thanks,
Jan Jezabek