TWebBrowser中:怎么判断点击后打开的网页是否打开完毕,谢谢!(150分)

  • 主题发起人 主题发起人 webbios
  • 开始时间 开始时间
W

webbios

Unregistered / Unconfirmed
GUEST, unregistred user!
TWebBrowser中:怎么判断点击后打开的网页是否打开完毕,谢谢!
 
while WebBrowser1.ReadyState <READYSTATE_COMPLETE do Application.ProcessMessages;

对于多个地址访问 为了区别开来 最好是在OnDocumentComplete事件中做一个全局变量CompleteNum:integer;
然后每完成一次就inc(CompleteNum)
所以当CompleteNum为1的时候 你要做什么 为2的时候你要做什么就方便了

或者把变量设为访问的地址CompleteURL:string;
比如我访问的第一个地址是www.google.com
那么你CompleteURL:='www.google.com';
这样判断究竟是打开哪个网页就容易了
 
没看懂,请问哪位帮我下,怎么实现谢谢
 
//-------------------------------Unit1.pas-------------------------------------
unit Unit1;

interface

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

type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
CompleteNum:integer;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
CompleteNum:=0;
WebBrowser1.Navigate(trim(Edit1.Text));
while WebBrowser1.ReadyState <READYSTATE_COMPLETE do Application.ProcessMessages;
Memo1.Lines.Add('我是1号,我通过判断WebBrowser1.ReadyState >READYSTATE_COMPLETE的结果向首长汇报,网页已经打开完毕,特此报告!')
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
Memo1.Lines.Add('CompleteNum: '+inttostr(CompleteNum));
Memo1.Lines.Add('我是2号,我通过WebBrowser1DocumentComplete事件向首长汇报,网页已经打开完毕,特此报告!')
if(pDisp=WebBrowser1.ControlInterface)then
begin
Memo1.Lines.Add('我是3号 我通过判断pDisp 网页已经打开完毕,特此报告!')
end;
end;

end.

//------------------------------Unit1.dfm--------------------------------------
object Form1: TForm1
Left = 181
Top = 84
Width = 790
Height = 633
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 16
Top = 496
Width = 65
Height = 13
Caption = #32593#22336#65306
end
object WebBrowser1: TWebBrowser
Left = 16
Top = 16
Width = 753
Height = 337
TabOrder = 0
OnDocumentComplete = WebBrowser1DocumentComplete
ControlData = {
4C000000D34D0000D42200000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
object Memo1: TMemo
Left = 16
Top = 368
Width = 753
Height = 121
ScrollBars = ssBoth
TabOrder = 1
end
object Button1: TButton
Left = 288
Top = 536
Width = 233
Height = 33
Caption = #35266#30475#26159#21542#25171#24320#23436#27605
TabOrder = 2
OnClick = Button1Click
end
object Edit1: TEdit
Left = 88
Top = 496
Width = 681
Height = 21
TabOrder = 3
Text = 'http://www.delphibbs.com/delphibbs/listq.asp'
end
end

//------------------------Project1.dpr----------------------------------------
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
 
如果要等所有的都完毕,比如 css, 图片等,那么在 OnDocumentComplete 事件中:
procedure THtmlForm.WebBrowserDocumentComplete(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant);
begin
if (pDisp = WebBrowser.ControlInterface) then
begin
// all completed
end;
end;
 
这样写代码如果不明白 那么我也没有办法了 呵呵~~~~~~
 
瓦 楼主跑哪里去了 莫非遇见转分的
 
君子爱分,取之有道!
少等,偶在看两位朋友的指点,一会结,合理分配两人!谢谢!
 
冰力不足,欠你个认情,不小心把分都给了Olivine了
我第一次打分,没看清楚,我该怎么办啊
 
呵呵,下次我再回答问题时,你不要再给分了[:D]
 

Similar threads

回复
0
查看
818
不得闲
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
880
DelphiTeacher的专栏
D
后退
顶部