Upgrade websnap app to delphi 2005 - CoInitialize error
We have a current product written开发者_如何转开发 in Delphi 6 websnap, which I'm attempting to upgrade to run under delphi 2005. It uses ADO, and the error on running is "CoInitialize has not been called". The only references I can find to this error point to IntraWeb and something called ServerController, which I'm not sure is relevant to me. Any number of calls of CoInitialize(nil) have no effect.
Am I wasting my time getting this to run or is it possible to run under 2005 -or a later release come to that?
CoInitialize
needs to be called within the thread that does the COM access (e.g. in any thread that accesses your database through ADO). It is called in the main thread by Delphi by default, but you need to call it explicitly in other threads.
Try calling it in the OnActivate
event, and call CoUninitialize
in the OnDeactivate
event.
Also make sure your ADOTables and ADOConnections are not open at design time. As otherwise the app will try to use COM before you've called CoInitialize
.
If all else fails - try overriding the web form's constructor and slip a CoInitialize
in there before you call inherited. Don't forget to call CoUninitialize
in the destructor.
精彩评论