Marshalling COM-objects to threads

Please discuss general Delphi programming topics here.

Marshalling COM-objects to threads

Postby smelis » October 8th, 2008, 4:57 pm

Hello all,

Does anybody have any experience with marshalling interfaces accross threads?

Problem description:

Application starts and creates 5 threads.
Each thread creates 5 "triggers", a COM-object and a timer.
OnTimer the thread loops through the triggers. If the triggers get triggered they call the COM-object belonging to its owning thread.

At this point I get message, saying that the COM-object was marshalled to a different thread. So I'm guessing I should be "marshalling" it to this thread (which I don't get, since the trigger operates within the context of the owning thread, which also owns the COM-object - but what the heck).

How should I do this? I've read the help and googled for it quite a bit, but I just don't understand the CoMarshalInterface() functions at all, so any help would be much appreciated.

If code is needed, I would be happy to post it here, but it is quite a lot, so I'll start work on a simple "produce.dpr"...

Thanks.
Stefan
smelis
Member
Member
 
Posts: 4
Joined: October 8th, 2008, 4:39 pm

Postby Kambiz » October 9th, 2008, 9:43 am

I have had tasks like this but never got such a message.

It is very difficult to guess what's wrong without seeing the code, but maybe this helps: If you create an object in the constructor of a thread, the main VCL thread is the owner.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby smelis » October 9th, 2008, 12:56 pm

Yes, I found that out yesterday. I've got the thread working now (by creating the COM-object at a later point than the thread-constructor), but now the problem's the other way around (when I call the COM-object from the main VCL thread).

Anyway, I'm still working on a little program that produces the error, but even that is a challenge, so I'll just post the entire code tonight..

Anyway thanks for the help so far..
smelis
Member
Member
 
Posts: 4
Joined: October 8th, 2008, 4:39 pm

Postby smelis » October 10th, 2008, 7:26 pm

Nevermind, I've found another way to do it... Anyway, thank you for your interest!
smelis
Member
Member
 
Posts: 4
Joined: October 8th, 2008, 4:39 pm

Postby Kambiz » October 10th, 2008, 10:06 pm

I'm glad to hear that.

Are you going to share it with us?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby smelis » October 28th, 2008, 7:54 pm

Messages :) PostThreadMessage() etc..
I figured I had to use them sooner or later, so here they were and now it works great!
smelis
Member
Member
 
Posts: 4
Joined: October 8th, 2008, 4:39 pm

Postby Kambiz » October 28th, 2008, 8:27 pm

Thank you!
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 8 guests

cron