Events in COM Server

Posted on 2005-03-18
Medium Priority
Last Modified: 2010-04-05

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?
Question by:protemus
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 10

Accepted Solution

Jacco earned 1000 total points
ID: 13581282
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
LVL 10

Expert Comment

ID: 13581292
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....
LVL 34

Assisted Solution

Slick812 earned 1000 total points
ID: 13582298
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?
LVL 10

Expert Comment

ID: 13583342
I registered the DLL using the Delphi menu Register ActiveX library.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question