Neven,

The implementation of IUnknown in TComponent is delegated to the Active-X
object that the component wraps around.  This is the reason your code fails.
VCL components don't expose an interface, and there is no point in
determining whether they do.  If you want to write your own component that
exposes their interfaces, you will need to override the AddRef, Release and
QueryInterface methods.  You will then need to use RTTI to determine whether
an object is a descendent of your class, and if it is, get the IUnknown
interface and call QueryInterface.  Would have been better if TComponent
implements the same mechanism as TInterfacedObject and have TOleControl do
the delegation instead?

As an aside, for those of you who have used interfaces, do you think
Borland's implementation can do with a bit of improvement.  I mean wouldn't
it be better to have a garbage collector rather than use the addref /
release mechanism, which BTW, calls an expensive kernel API to increment /
decrement the reference count.  So here is another tip - if you don't need
your implementation classes to be thread safe, you can override AddRef and
Release to bypass the use of the kernel api calls - its faster.

Regards,
Dennis.

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to