我在主窗体里把弹出的网页弹出在子窗体里:
procedure TForm1.WebBrowser1NewWindow2(Sender: TObject;
  var ppDisp: IDispatch; var Cancel: WordBool);
  var w,h:integer;
  var
  Doc:IHTMLDocument2;
  Obj:IHTMLScriptElement;
  i:Integer;
begin
    if not Assigned(childfrm) then
    childfrm := Tchildfrm.Create(Self);
    
    childfrm.Parent := Form1;
    childfrm.Caption:= cfrm_name;
    w:=  (form1.width- childfrm.Width) div 2; h:=(form1.height-childfrm.Height) div 2;
    childfrm.Top:=h;
    childfrm.Left:=w;
    ppDisp:=childfrm.WebBrowser1.DefaultDispatch;
    childfrm.Show;
   
end;procedure Tchildfrm.FormShow(Sender: TObject);
var
  Doc:IHTMLDocument2;
  Obj:IHTMLScriptElement;
  i:Integer;
begin
  while WebBrowser1.ReadyState<>4 do
    Application.ProcessMessages;  Doc:=WebBrowser1.Document as IHTMLDocument2;
  if Assigned(WebBrowser1.Document) then showmessage('有分配值');  //这里得不到Document的值,
  
  for i:=0 to Doc.scripts.length-1 do  //这里就报错了。
  begin
    Obj:=Doc.scripts.item(i,varEmpty) as IHTMLScriptElement;
    ShowMessage(Obj.text);
  end;
end;所以就读不到JS的文本,要如何做才好呢?请大家帮帮忙。