Board index » delphi » D4, Microsoft Script Control and OLE Automation

D4, Microsoft Script Control and OLE Automation


I have managed to get scripting working in my Delphi 4 C/S application
using the Microsoft Script Control. However, I have run into a problem.

My application includes an OLE Automation server so I can present
methods and properties to the Script Control for use in scripting. I
have done this by implementing an OLE Automation server by going to
File/New/ActiveX/Automation Object. I then added properties and methods
to the interface and implemented their code.

Finally, I needed to add my automation server to the script control so I
used CreateOLEObject('Project.TAutoServer') and passed the result to the
script control using it's AddObject method.

This all works fine, and the properties and methods are available to the
scripting engine. The problem comes when I close the application. If I
have run scripting code that made use of my automation server, I get the
following error when I close the application:

"There are still active COM objects in this application. One or more
clients may have references to these objects, so manually closing this
application may cause those client applications(s) to fail."

I don't know much about COM, so I have no real idea why this error
occurs. There is a method of the Script Control that is supposed to
release objects that have been added to it ( Reset ), but that makes no

I have tried exactly the same application in Delphi 3. The program works
fine and the error does not appear ( but I don't really want to go back
to Delphi 3 ).

So, does anyone know what the error means, or what could be causing it?
or even better, how do I get rid of it?

Many thanks,

+-- Alex Wingrove / --+


Re:D4, Microsoft Script Control and OLE Automation


I seemed to have managed to solve my own problem, so I thought I would
share the answer with everyone.

I was using CreateOLEObject to get an instance of my Automation server
and pass it to the Microsoft Script Control. I have now changed it so
that I have a member of my form declared as:

        AutoServer: TAutoServer;

where TAutoServer is my OLE Automation object. I then do the following
in the form OnCreate:

        AutoServer := TAutoServer.Create;

Now I can pass AutoServer to the script control and still have access to
it. This means I can release the object myself in the form OnClose, like


And now I don't get the error message pop up when the application

If any one wants an example of this, let me know.


+-- Alex Wingrove / --+

Other Threads