Board index » delphi » COM in a thread question

COM in a thread question

Hi,

I am having a strange problem with COM in a thread.

I have a RDM that is defined to implement IDataStreamProvider - an interface
required by another piece of code I wrote.

In the RDM I do the following:

   ids := Self; // Self as IDataStreamProvider;
   DataEngine.DataStreamProvider := ids;

This works great.

I now want to move this code to execute in a separate thread.

The thread calls OleInitialize in it's constructor and it calls
OleUnInitialize in it's Destroy method.

I do the following in it:

I create a TAutoObject descendent that implements IDataStreamProvider and
call it ThreadStreamer. Later I write the following code:

   ids := ThreadStreamer as IDataStreamProvider; // Self as
IDataStreamProvider;
   DataEngine.DataStreamProvider := ids;

Surprisingly, I get an error message EOleSysError - Type Mistach on the 2nd
line (DataEngine.DataStreamProvider...)

In boh cases DataEngine is defined as an OleVariant and is created using the
same code:

   DataEngine := CreateOleObject('DTECtrl.DTEActivator');

Any ideas what I am doing wrong?

Thanks,
    Ron.

 

Re:COM in a thread question


Found it. Wrote the answer in the multi-tier newsgroup.

Ron.

Quote
"InfoPath, Inc" <infop...@transport.com> wrote in message

news:9358ib$le714@bornews.inprise.com...
Quote
> Hi,

> I am having a strange problem with COM in a thread.

> I have a RDM that is defined to implement IDataStreamProvider - an
interface
> required by another piece of code I wrote.

> In the RDM I do the following:

>    ids := Self; // Self as IDataStreamProvider;
>    DataEngine.DataStreamProvider := ids;

> This works great.

> I now want to move this code to execute in a separate thread.

> The thread calls OleInitialize in it's constructor and it calls
> OleUnInitialize in it's Destroy method.

> I do the following in it:

> I create a TAutoObject descendent that implements IDataStreamProvider and
> call it ThreadStreamer. Later I write the following code:

>    ids := ThreadStreamer as IDataStreamProvider; // Self as
> IDataStreamProvider;
>    DataEngine.DataStreamProvider := ids;

> Surprisingly, I get an error message EOleSysError - Type Mistach on the
2nd
> line (DataEngine.DataStreamProvider...)

> In boh cases DataEngine is defined as an OleVariant and is created using
the
> same code:

>    DataEngine := CreateOleObject('DTECtrl.DTEActivator');

> Any ideas what I am doing wrong?

> Thanks,
>     Ron.

Other Threads