[英]Using CoInitialize in a Delphi thread
I am using TIdHttp and TXMLDocument inside a thread in a Delphi program. 我在Delphi程序的线程内使用TIdHttp和TXMLDocument。 Now I want to know:
现在我想知道:
TIdHTTP
has no COM dependency. TIdHTTP
没有COM依赖性。
TXMLDocument can have a dependency on COM. TXMLDocument 可以依赖于COM。 On Windows, out of the box it is a wrapper around Microsoft's MSXML ActiveX component, which uses COM.
在Windows上,它是Microsoft MSXML ActiveX组件的包装,该组件使用COM。 If you use another DOM vendor (for example, OmniXML, available from XE7) then there is no COM dependency.
如果使用其他DOM供应商(例如,XE7的OmniXML),则没有COM依赖性。 You can control this by setting the
DefaultDOMVendor
global variable. 您可以通过设置
DefaultDOMVendor
全局变量来控制它。
CoInitialize
and CoUninitialize
must be called once from within the thread context. 必须从线程上下文中一次调用
CoInitialize
和CoUninitialize
。 Typically in the Execute()
method of TThread
, as seen in this example flow: 通常在
TThread
的Execute()
方法中,如本示例流程所示:
procedure TMyThread.Execute; begin try CoInitialize(nil); try while not Terminated do begin DoWorkThatMayUseCOM; end; finally CoUninitialize(); end; except on E: Exception do // log exception Log(E); end; end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.