还有一个问题,可以追加分的,请帮一下var
  doc:IHTMLDocument3;
  tables:IHTMLElementCollection;
  Table1 :HTMLTable;
   Row :HTMLTableRow;
    Cell : HTMLTableCell ;
   i,j:integer;
begin
  doc:=WebBrowser1.Document as IHTMLDocument3;//呵呵,这儿可不是IHTMLDocument2
  tables:=doc.getElementsByTagName('table');
  For i:=1 To Table1.rows.length - 1 do   
  begin
      row:=Table1.rows(i);
.............为什么在编译时,      row:=Table1.rows(i); 总是出错,到底错在那里呢?
另外,还想请教一下
VB 语句有:   For Each Table1 In Tables我在DEPHI 应该怎样写这个呢?

解决方案 »

  1.   

    var
      doc:IHTMLDocument3;
      tables:IHTMLElementCollection;
      Table1 :HTMLTable;
       Row :HTMLTableRow;
        Cell : HTMLTableCell ;
       i,j:integer;
    begin
      doc:=WebBrowser1.Document as IHTMLDocument3;//呵呵,这儿可不是IHTMLDocument2
      tables:=doc.getElementsByTagName('table');
      For i:=1 To Table1.rows.length - 1 do
      begin
        row:= Table1.rows.item(i, i) as HTMLTableRow; //这样可以,不知道能否得到正确结果
      end;
    end;Delphi中没有类似VB中For Each Table1 In Tables的语句
    用循环实现吧
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      doc:IHTMLDocument3;
      tables:IHTMLElementCollection;
      Table1 :HTMLTable;       
      Row :HTMLTableRow;
      Cell : HTMLTableCell ;
      i,j:integer;
    begin
      doc:=WebBrowser1.Document as IHTMLDocument3;//呵呵,这儿可不是IHTMLDocument2
      Tables:= doc.getElementsByTagName('table');
      if Tables = nil then
       exit;     
      table1 := Tables.item(0,0) as HTMLTable;
      if table1 = nil then
        exit;
      For i:=0 To Table1.rows.length - 1 do
      begin
          if Table1.rows.item(i,i) = nil then
              continue;   
          row:= Table1.rows.item(i,i) as HTMLTableRow;
          for j := 0 to row.cells.length -1 do
          begin
            if row.cells.item(j,j) = nil then
              continue;
            Cell := row.cells.item(j,j) as HTMLTableCell;
            //Memo1.lines.Add(Cell.innerText);
          end;
      end;
    end;
      

  3.   

    For Each In 的语法在D7里没有,在D2006里有类似的 for  in  do。