Link to home
Start Free TrialLog in
Avatar of foxvision
foxvision

asked on

Inherit COM in Delphi?

Dear experts,

Using VB, I could do a new ActiveX DLL, import any COM objects, then I could start to write codes which actually overrite existing methods in the COM, like this:

Option Explicit

Implements Desktop.IProteanTool
'This function is activated from protean UI
Private Sub IProteanTool_Launch(ByVal aToolContext As Desktop.IProteanToolContext)
    Set aToolContext = Nothing
    frmContractCreditLimitEntry.Show 1
End Sub

With this, I override what is originally in IProteanTool_Launch and show my own form.

How can I do this in Delphi? When I imported the COM as TLB type library, all I can see is:

// *********************************************************************//
// DispIntf:  IProteanTool
// Flags:     (4096) Dispatchable
// GUID:      {9AF5DC81-2498-11D1-8C31-0000C0328CEF}
// *********************************************************************//
  IProteanTool = dispinterface
    ['{9AF5DC81-2498-11D1-8C31-0000C0328CEF}']
    procedure Launch(const aToolContext: IProteanToolContext); dispid 1;
  end;

Please advise. Thanks.

Regards,
Fox
ASKER CERTIFIED SOLUTION
Avatar of rondi
rondi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of foxvision
foxvision

ASKER

Dear Rondi,

Thanks for your guidance. Let me experience the codes above and I will get back to you very soon.

Regards,
Fox
Dear Rondi,

I tried the code yesterday and there are a few points which I don't quite understand.

When you said:

Make a new COM object named ProteanToolEx.
The COM object should implement the IProteanTool interface.

What does the above mean? How should the new COM object ProteanToolEx implement IProteanTool interface?

As I indicated in the 1st post, IProteanTool is a dispinterface.

2nd point:

You said:

TProteanToolEx = class(TComObject, IProteanTool, IProteanToolEx.....)
private
 FProteanTool: IProteanTool;
protected

I got a compilation error saying that IProteanTool is not an interface and it is expecting an interface. Again, the code

CoProteanTool.Create

simply not possible because there is no CoProteanTool as it is a dispinterface.

Hmm?!

Regards,
Fox
Hey Fox,

I assumed the code you posted the first time was just
a small part of the Type Library import unit. If that's all there was, then u got a problemo!
You're gonna need to import the ProteanTool type library
again, so you get the full unit with interfaces, dispinterfaces and CoClasses. You won't be able to do anything with just dispinterfaces.

So, start a new ActiveX Library DLL project. Import the protean type library. Go to File -> New -> Other -> [ActiveX] COM object. In the COM object wizard, add the IProteanTool interface to the new object's implemented interfaces (you may have to browse for the type lib first). Hit OK, and you're ready to go.
Go to the new unit and write code for the launch procedure.

You can add a new form to your project and show it from your new COM object's Launch procedure.

rondi.
Dear Rondi,

I think I still can't did what you said because I look through the entire TLB file and ProteanTool is a DispInterface.

Your answer let me learn some new things in COM as well and you deserve the points.

Though I just marvel at VB that it has the capability to do what I want so easily. I always believe that whatever can be done in VB is surely no problem in Delphi, well, I guess I am wrong this time, ha.

Regards,
Fox