首页 > 代码库 > 多线程操里操作webbrowser的 Frames

多线程操里操作webbrowser的 Frames

多线程操里操作webbrowser的 Frames有这样一个函数,直接在窗体中运行正常,但放到线程里一到frames就报错procedure TForm1.fillframese1(webbrowser:TWebBrowser;params:TStrings;frameindex:integer);var  Tabi:Integer;  doc:IHTMLDocument2;  Collection:IHTMLElementCollection;  Element:IHTMLElement;  frames:IDispatch;  framew:IHTMLWindow2;  i:OleVariant;  s:string;  ii,divi:Integer;  input:IHTMLInputElement;  docii:HTMLDocument;  iframe:IWebBrowser;begin  try    doc:=Webbrowser.document as IHTMLDocument2;    i:=6;    doc.all ;    frames:=doc.frames.item(i);    framew:=frames as IHTMLWindow2;    docii:=framew.document as HTMLDocument;    collection:=docii.all.tags(iframe) as IHTMLElementCollection;    //ShowMessage(IntToStr(Collection.length));    for ii:= 0 to collection.length -1 do    begin      iframe:= Collection.item(ii,varEmpty) as IWebBrowser; //在网上查过不少文章,最后自己尝试成功,关键就是这里。      doc:=iframe.document as IHTMLDocument2;      Element:=doc.body as IHTMLElement;    end;     //总结:获取Webbrowser的iframe的内容,需要把iframe元索强制转换为iwebbrowser接口,     //之后,还要强制转换为ihtmlelement接口才可以成功访问iframe里面的元素,否则程序运行出错;  except  on e:exception do    begin      showmessage(fillframese1: +params.Names[i]+ :+e.Message);    end;  end;end;线程外正常,但放到IdTCPServer.Execute里调用,执行到这句就报错frames:=doc.frames.item(i);并且已经加上  CoInitialize(nil); OleInitialize(nil);不知道大家有没有遇到过,有什么解决方法?