Using Delphi 7, whenever I try to do any database work inside of a thread I get this error:
"CoInitialize has not been called"
I used a simple code containing an ADOConnection.Open inside the thread.
But the same code works fine if it's used in a form any ideas?
@mjn: I'm not allowed to comment your remark in the previous answer, so I created a new answer: calling CoInitialize from the constructor is one of typical error programmers do.
Constructor is executed in a context of another thread, but you need to initialize COM on the current thread (when a thread procedure is running i.e. as part of Execute method) see
procedure TYourThread.execute;
begin
CoInitialize(nil);
FConnection:=TConnection.Create(...);
try
ThreadCode ....
finally
FConnection.free;
CoUninitialize;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With