Board index » delphi » constructors and destructors in COM objects

constructors and destructors in COM objects

Hello,

I've got several questions.

1. I'd like to have a constructor and a destructor in my COM-interface
that are automatically executed when an object is being created and
destroyed

e. g.

  TAutoObjectFactory.Create(ComServer, TComClass, Class_ComClass,
                            ciMultiInstance);

should call a constructor in TComClass.

Right now, I have a method called Init which I call manually but it
would be good to automate that.

2. Sometimes I have problems when editing and afterwards generating type
libraries in Delphi 3 such that a property defined as read/write is
suddenly read only. I then have to redo the change and reset the
property manually to read/write (even if I never changed it).

Anybody has similar problems?

3. When I call DispatchInvokeError, it generates an exception for a
status code. I'd like to set the source where the problems come from
(there is a field bstrSource). However, the underlying exception class
EOleSysError does not report the bstrSource. In fact it reports not very
much useful, just the error text.

Is there a way to circumvent this or a better metho? Of course I can
always write my own exception class, but maybe there are other ways too.

TIA,

Rudi

 

Re:constructors and destructors in COM objects


Quote
Rudolf Ziegaus wrote in message <368362C3.1FA8A...@bingo.baynet.de>...
>1. I'd like to have a constructor and a destructor in my COM-interface
>that are automatically executed when an object is being created and
>destroyed

>e. g.

>  TAutoObjectFactory.Create(ComServer, TComClass, Class_ComClass,
>                            ciMultiInstance);

>should call a constructor in TComClass.

Rudolf,

 The TAutoObjectFactory.Create does not creates object itself ! It registers
in only (in the Delphi com-classes manager). The object creation occurs when
the client requests your object. You can not override a constructor to add
your initialization code because TAutoObject.Create is not virtual but you
can use the Initialize method of TAutoObject. This metod is virtual and it
is called at the creation of object. Override it to add your own
initialization code.
To execute your code at object destroing use a common way namely override a
destructor and add your code there.

Be happy,

--
Alexey A. Dynnikov <al...@chat.ru>
http://www.chat.ru/~aldyn
ICQ 18267212

Re:constructors and destructors in COM objects


Thanks for your help. I was not aware of the Initialize method.

Rudi

Alexey A. Dynnikov schrieb:

Quote
> Rudolf Ziegaus wrote in message <368362C3.1FA8A...@bingo.baynet.de>...
> >1. I'd like to have a constructor and a destructor in my COM-interface
> >that are automatically executed when an object is being created and
> >destroyed

> >e. g.

> >  TAutoObjectFactory.Create(ComServer, TComClass, Class_ComClass,
> >                            ciMultiInstance);

> >should call a constructor in TComClass.

> Rudolf,

>  The TAutoObjectFactory.Create does not creates object itself ! It registers
> in only (in the Delphi com-classes manager). The object creation occurs when
> the client requests your object. You can not override a constructor to add
> your initialization code because TAutoObject.Create is not virtual but you
> can use the Initialize method of TAutoObject. This metod is virtual and it
> is called at the creation of object. Override it to add your own
> initialization code.
> To execute your code at object destroing use a common way namely override a
> destructor and add your code there.

> Be happy,

> --
> Alexey A. Dynnikov <al...@chat.ru>
> http://www.chat.ru/~aldyn
> ICQ 18267212

Other Threads