这是一个不太完美的方案,并没有用到多线程:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
EditAddress: TEdit;
ButtonGo: TButton;
ButtonStop: TButton;
procedure ButtonGoClick(Sender: TObject);
procedure ButtonStopClick(Sender: TObject);
private
{ Private declarations }
FDownAbort: Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ButtonGoClick(Sender: TObject);
var
I: Integer;
begin
ButtonGo.Enabled := False;
try
FDownAbort := False;
WebBrowser1.Navigate(EditAddress.Text);
while (WebBrowser1.ReadyState <> READYSTATE_COMPLETE) and not FDownAbortdo
for I:= 0 to 1000do
Application.ProcessMessages;
if WebBrowser1.ReadyState = READYSTATE_COMPLETE then
ShowMessage('DownFinished')
else
ShowMessage('DownStopped');
finally
ButtonGo.Enabled :=True;
end;
end;
procedure TForm1.ButtonStopClick(Sender: TObject);
begin
WebBrowser1.Stop;
FDownAbort := True;
end;
end.