• delphi webbroser循环读取网页(来自msdn的判断网页载入完毕的方法)


    源代码如下:

    unit Unit2;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, OleCtrls, SHDocVw;

    type
      TForm2 = class(TForm)
        WebBrowser1: TWebBrowser;
        Button1: TButton;
        ListBox1: TListBox;
        procedure FormShow(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure WebBrowser1DocumentComplete(ASender: TObject;
          const pDisp: IDispatch; var URL: OleVariant);
      *******
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form2: TForm2;
      ok:Boolean;

    implementation

    {$R *.dfm}
    //{$APPTYPE CONSOLE}

    procedure TForm2.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin
    //循环读取网站
    for I := 0 to ListBox1.Count-1 do
    begin
      WebBrowser1.Navigate(ListBox1.Items[i]);

      while True do
      begin
        if ok then break;
        Application.ProcessMessages();
      end;
      ok:=false;
    end;

    end;

    procedure TForm2.FormShow(Sender: TObject);
    var
      filename:string;
      myfile:TextFile;
      s:string;
      i:integer;
    begin
    //全局变量初始化
    ok:=false;
    //初始化列表框
    filename:=ExtractFilePath(Application.ExeName)+'\list.txt';
    AssignFile(myfile,filename);
    try
      Reset(myfile);
    except
      on e:Exception do
      begin
        ShowMessage(e.Message);
        Rewrite(myfile);
      end;

    end;
    i:=0;
    while not SeekEof(myfile) do
    begin
      Readln(myfile,s);
      ListBox1.Items.Add(s);
      inc(i);
    end;
    CloseFile(myfile);

    end;

    procedure TForm2.WebBrowser1DocumentComplete(ASender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    begin

      if(pDisp=WebBrowser1.Application) then
      begin
        //Writeln('ok');
        ok:=true;
      end;
    end;

    end.
     

    源代码下载:http://www.rayfile.com/files/264444e1-1488-11df-9b90-0015c55db73d/

  • 相关阅读:
    win7下的nginx小demo
    破解navicat
    MVC下用C#实现Excel导出
    使用IE10登录,URL出现SessionId的解决办法
    C#错误:The Controls collection cannot be modified
    更改数据库排序规则
    windows server 2008 r2电脑历史操作记录
    jquery easyui无法绑定下拉框内容
    Jquery实现自动提示下拉框
    CLSID {91493441-5A91-11CF-8700-00AA0060263B}错误
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668553.html
Copyright © 2020-2023  润新知