我打开一个页面,并在这个页面上进行查找一个指定的字符,用的是一下的方法:
procedure TURLFrm.FindToEnd(sFindText: String);
var
  TxtRange: IHTMLTxtRange;
begin
  if not Assigned(MainBrowser.Document) then Exit;
  TxtRange:=(WebBrowser.Document as IHTMLdocument2).selection.createRange as IHTMLTxtRange;
  TxtRange.setEndPoint('StartToEnd', TxtRange);
  try
    if not TxtRange.findText(Edit1.Text, 1, 0) then
    begin
      ShowMessage( '没找到! ');
      Exit;
    end;
    TxtRange.select;
    TxtRange.setEndPoint('StartToEnd', TxtRange);
  except
  end;
end;
但是我发现,找到第一个匹配的字符没有问题,但是当找第二个的时候,就会出现错误。错误位置在TxtRange.select;请问哪位大侠遇到过这样的问题?

解决方案 »

  1.   

    什么错误信息,以下代码测试正常,查找163页面的新闻字样var
      TxtRange: IHTMLTxtRange;
    begin
      if not Assigned(WebBrowser1.Document) then Exit;
      TxtRange:=(WebBrowser1.Document as IHTMLdocument2).selection.createRange as IHTMLTxtRange;
      TxtRange.setEndPoint('StartToEnd', TxtRange);
      try
      if not TxtRange.findText('新闻', 1, 0) then
      begin
      ShowMessage( '没找到! ');
      Exit;
      end;
      TxtRange.select;
      TxtRange.setEndPoint('StartToEnd', TxtRange);
      except
      end;
    end;
      

  2.   

    错误是:
    ---------------------------
    Debugger Exception Notification
    ---------------------------
    Project Brower.exe raised exception class EOleException with message '由于出现错误 800a025e 而导致此项操作无法完成。'.
    ---------------------------
    Break   Continue   Help   
    ---------------------------就在TxtRange.select;提示错误。不过也不是每次都出,例如我在腾讯网,查找'QQ'字符的时候,都是查到第10个或者第14个的时候才出现这个错误。我的源码为:
    TxtRange:=(MainBrowser.Document as IHTMLdocument2).selection.createRange as IHTMLTxtRange;
      TxtRange.setEndPoint('StartToEnd', TxtRange);
      try
        if not TxtRange.findText('QQ', 1, 0) then
        begin
          Result:=tftNotfind;
          Exit;
        end;
        TxtRange.select;
        TxtRange.setEndPoint('StartToEnd', TxtRange);
        Result:=tftSuccess;
      except
        Result:=tftError;
      end;
      

  3.   

    用bdmh说的方法,问题依旧。---------------------------
    Debugger Exception Notification
    ---------------------------
    Project Brower.exe raised exception class EOleException with message '由于出现错误 800a025e 而导致此项操作无法完成。'.
    ---------------------------
    Break   Continue   Help   
    ---------------------------补充一句我用的是TEmbeddedWB控件,不过在查找的时候,起始并没有使用TEmbeddedWB的相关东西。