Re: getting an event handler from a active-x dll dispinterface



I used EventSinkImp to create a component based on the event-object.
The component is only very simple, it just has the youhaveamessage
event and name and tag property in the object inspector.
The event is not fired on incoming messages when i create an object
(which is logical since not even a port is opened or whatever).
The other class of which I did succesfully create an communication
object does have an openport, sendmessage,getmessage function. So one
way or the other I have to connect the two.
The event object-class has a connect method:
Connect (const ASource: IUnknown);

I don't know what an IUnkNown is but if I use the (connected and
functioning) communcation object
as a parameter it does compile, it does run but it doesn't fire
events.

I know i display utter ignorance here. I don't want to become an
activeX expert. I just have some nail biting problems getting the
communication with a device going and just want to get this job done.

Is there some general way in which the event and communication object
are to be connected or is it impossible to say something sensible
about it without seeing the complete code?

On Mon, 25 Dec 2006 15:46:26 +0100, "Maarten Wiltink"
<maarten@xxxxxxxxxxxxxxxxxx> wrote:

"HanslH" <no@xxxxx> wrote in message
news:201uo25ruadn1ck40tbknkui1aaj6i7m1s@xxxxxxxxxx
[...]
The events-object(?) is formulated in the wrapper something like this:

=======================================
SomelEvents = dispinterface
['{blablabla}']
procedure Youhaveamessage; dispid 1;
end;
========================================

How do I use this in delphi?

You write your own class that implements this interface, create an
instance of it, and register it with the object abstracting the
device through its interface.

When the device object wants to fire an event, it calls the
'YouHaveAMessage' method through the interface reference you
gave it.

It's not very different from having a component class and setting
an event handler (a property) to a method reference in probably your
form class, only _everything_ is done through interfaces. That way,
your (and their) classes don't need to derive from known base classes.

Groetjes,
Maarten Wiltink

.