I have a block with sections initialization and finalization . This block contains a complex object that is created in initialization and destroyed in finalization . However, this object also contains an ADO connection. This makes it a problem when using this in threads, since ADO is COM, and it needs to be initialized for each thread.
This is how I process this instance of the global object now:
uses ActiveX; ... initialization CoInitialize(nil); _MyObject:= TMyObject.Create; finalization _MyObject.Free; CoUninitialize; end.
This only works in the main thread. Any other thread will not be able to access it and will return a CoInitialize has not been called exception.
How do I get around this to make this block thread safe? I need a way to bind every creation / destruction of any created thread, and each thread will have to reference a different instance of this object. But how to do that?
multithreading initialization delphi ado delphi-xe2
Jerry dodge
source share