Jump to content
michastro

Create a class that implements a DispInterface

Recommended Posts

Posted (edited)

Hello,

I have a DispInterface imported from an external library:

ITelescopeV3 = dispinterface ['{A007D146-AE3D-4754-98CA-199FEC03CF68}'] 
.
.
end;

I would like to create a class of the type:

TTelescope = class(TAutoObject, ITelescopeV3)

But it doesn't work, 'Interface type required'.

I'm pedalling a bit here!

Thanks for your help

Michel

Edited by michastro
  • Like 1

Share this post


Link to post

dispinterface isn't a keyword; Use interface instead:

ITelescopeV3 = interface 
['{A007D146-AE3D-4754-98CA-199FEC03CF68}'] 
.
.
end;

 

Share this post


Link to post

But I haven't write the dispinterface, it's coming from an external library. And I confirm that dispinterface is a keyword, it is written in bold in the listing.

 

Share this post


Link to post
Posted (edited)

It looks like you are trying to create an Automation Object with dual ole automation interfaces.

 

Delphi has a wizard that can generate the initial project.

 

The project will include a .ridl file from which you visually design a Type Library.

 

The Type Library designer can generate an implementation stub with all the user defined interfaces.

 

These interfaces are derived from IDispatch, which are your so called DispInterfaces.

 

 

Edited by David Champion
typo

Share this post


Link to post

Thanks David,

Unfortunatly I don't know how to use these external library in the Type Library.

Share this post


Link to post

Okay, so you are trying to interface to an external COM library. From the name of the interface I'm guessing this is the interface:

https://ascom-standards.org/Help/Developer/html/T_ASCOM_DeviceInterface_ITelescopeV3.htm

 

As you can read in the documentation...

https://ascom-standards.org/Help/Developer/html/e7734c14-0562-4010-b0c9-ddb5055cd318.htm

...there should be a type library that you can use.

 

The easiest way to use this type library is to have Delphi create a wrapper for you:

  1. From the Delphi IDE menu, select Component->Import Component...
  2. Select Import a Type Library
  3. Find the type library in the list or select Add and find it on your disk.
  4. Edit the Unit Dir Name to place the generated wrapper source code in your project source folder.
    I do not recommend that you select "Generate Component Wrappers".
  5. Select Add unit to <name of your project> project.

Delphi will now have created a source file containing all the interfaces, dispinterfaces, enums, coclasses, etc. of the type library.

In order to communicate with the library you will first have to create an instance of a COM object from it. There should be a function in the generated source that will do that for you but since I don't know the library I can't tell what the name of that function is.

If you have some example code, in C, C++ or VB, it should be easy to see from that what you need to do. Post it if you have it and we can take it from there.

Share this post


Link to post

It's more complex than this ...

The wrapper (tlb) (it's the "ASCOM Device Interfaces for Platform 6") expose only the interfaces, there is a "scopeSim" that expose similar interface and a full class.

 

He must explorer all type libraries registered about that (or read the full documentation) and find the class that use that interface (or how to use if it's exposed in the documentation or in the examples like @Anders told).

Bye

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×