• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

Events in COM Server

I have a simple COM object, but I am unable to get its events in a client....

The following lines are the problem in the COM server implementation:

//  Initialize
procedure TMyCOMObject.Initialize;
  inherited Initialize;
  FConnectionPoints := TConnectionPoints.Create(Self);
  if AutoFactory.EventTypeInfo <> nil then
    FConnectionPoint := FConnectionPoints.CreateConnectionPoint(
      AutoFactory.EventIID, ckSingle, EventConnect)
  else FConnectionPoint := nil;

The problem is that AutoFactory.EventTypeInfo is nil.... why is this?  How do I make sure my factory knows about my events?
  • 3
2 Solutions
I have tried the follwing but can't get it to work either :-( I thought it was a straigt forward thing to do, but it seems more difficult.

To make sure you followed the right steps (in Delphi7 that is):
1. make ActiveX Library
2. add Type Library
3. add Automatic Object (enabling "Generate Event support code") and call it MyCOMObject
4. on IMyCOMObject add a TestEvent method with no parameters
5. on IMyCOMObjectEvents add a OnTestEvent method also with no parameters
6. Press refresh on the Type Lib editor and go to Unit1 (where TMyCOMObject is implemented)
7. Create the following method

procedure TMyCOMObject.TestEvent;

8. Build and register this COM DLL

Then I wanted to create a client which consumes this event but I did not succeed...

Regards Jacco
I thought I had to create a class that implements IMyCOMObjectEvents (which was not possible since only the dispatch interface is in the typelib so I copied this interface stripped disp of dispinterface and added safecall) so I created a new class implementing IDispatch and my new IMyCOMObjectEvents and did all the implementations.

Then I created a MyComObject using CreateOleObject('MyLib.MyComObject ')
Created my event handler object
Connected it to MyComObject using a call to InterfaceConnect
Called TestEvent
But it crashes....
hello protemus , ,  the code you have posted looks correct to me,  , it looks like the "Standard" code generated by the com creation wizard in Delphi. . .
However, there are factors that come into play for a Client and Server to use the "Events", The client must connect to the server and have a workable Interface to the server's COM. .  I believe that the connection (if set up correctly) will initialize all of the things needed to have the event work. .

Jacco, I believe your client crashes because your "COM" Interface is Not registered in the system. You may want to start com server with a program insted of a Library, you just run the program and it automatically registers the COM interface with the system, I can not remember if a library will auto register?
I registered the DLL using the Delphi menu Register ActiveX library.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now