Solved

Problem with RegisterActiveObject

Posted on 2008-10-08
2
807 Views
Last Modified: 2012-06-21
I'm trying to get RegisterActiveObject to behave. Doing it the way that's been described here

type TAutoClass = class (TAutoObject,IMyInterface)
private
  Cookie : longint;
public
  procedure Initialize; override;
...
procedure TAutoClass.Initialize;
  begin
    inherited Initialize:
    RegisterActiveObject (Self As IUnknown, Class_MyClass, ActiveObject_Weak, Cookie);
  end;

gives two 'incompatible types', IUnknown/TAutoClass and Ole2.TGUID/System.TGUID.
I can make it compile OK by writing

    RegisterActiveObject (IUnknown(Self), Ole2.TGUID(Class_MyClass), ActiveObject_Weak, Cookie);

but when I actually use the thing something goes drastically wrong and I'm seeing recursive calls
into the initialize routine, the RegisterActiveObject seems to be causing a new Initialize. What basic
mistake am I making here?
0
Comment
Question by:mikrobe
2 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 22677142
From Delphi 5 help :-

When creating an OLE automation object (an object derived from the TAutoObject class in the Oleauto unit) the file that defines that object must call Automation.RegisterClass, passing a record of type TAutoClassInfo. The Automation manager then handles all interactions between the automation object and the OLE automation API.


0
 

Accepted Solution

by:
mikrobe earned 0 total points
ID: 22677243
I think the TAutoObject I'm using here is actually the one defined in ComObj. However I do think there is some confusion about which versions of the various pieces involved are being used (hence the confusion about the TGUID type). The Ole2 module was being referenced in my 'uses' (for historical reasons :-) and removing that not only persuaded Delphi to accept the original syntax but also got rid of the inifinite loop in the Initialize routine. No idea what the problem *really* was other than that Delphi was obviously interpreting things the wrong way when Ole2 was in the mix.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now