I have an ADO Recordset object created in a background thread:
var conn: TADOConnection; rs: _Recordset; begin conn := CreateDatabaseConnection(); rs := conn.Execute(CommandText, cmdText, []); conn.Free;
And then the Recordset is passed to my "main" stream:
procedure ExecuteComplete(var msg: TMessage); message WM_HeresTheRecordsetYouAskedFor; var rs: _Recordset; begin rs := _Recordset(msg.wParam);
I could also do:
var global_Recordset: _Recordset; var conn: TADOConnection; begin conn := CreateDatabaseConnection(); global_Recordset := conn.Execute(CommandText, cmdText, []); conn.Free; end;
In any case, the thread that did not create , created the COM object, now uses it. From the main stream:
global_Recordset .Fields['TheTimeIs'].Value;
COM denies access to COM objects from apartments (in this case: threads) that did not create the object.
What is the correct way to marshal the interfaces of a COM object while working across apartment boundaries?
source share