I have some inherited code for opening IE and I have some troubles, here is what I have: IEUnit.pas (no form) has routines for LoadIE and OpenIE OpenIE is called from separate thread and it looks like this
I would like to have "global" ie variable in the unit and to write LoadIE routine like this : LoadIE should be called from FormCreate (main thread) It should just create "global" ie object
so the OpenIE function doesn't need to create it, just to use it (purpose is to speed things up) So problem is how to access same OLE object from 2 different threads, one creates the object, the other one uses it. When I write code that doesn't take care of threads I get an error exception class EOleSysError with message 'The application called an interface that was marshalled for a different thread' How should I do it, to take care of threads (I'm not experienced with threads, some reading and video links are welcome). Thanks in advance | |||
add comment |
As you know, because it was the subject of your previous question, you need all calls to the COM object to be made from the same thread. The obvious choice is the main GUI thread. So, create the Assuming you are using a modern version of Delphi with support for anonymous methods you'd write it like this:
| |||||
|
MTA model COM servers can only be used from within their associated apartment. Here's the explanation of the error with the following advice:
| |||||||||||||||||||||
|
use CriticalSection to wrap all calls to the OleObject. also use Synchronize to call from the "other" thread to the main UI thread (this is why you get the exception). | |||||||||
|
联系客服