zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    桌面应用程序ClickOne打包部署
    Linux系统基础5周入门精讲(Linux发展过程)
    Linux系统基础5周入门精讲(服务器介绍)
    算法进阶--动态规划
    行为型模式
    结构型模式
    设计模式
    哈希表--树
    数据结构
    查找排序相关面试题
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668553.html
Copyright © 2011-2022 走看看