IE浏览器中的“前进”,“后退”按钮应怎么设置(5分)

  • 主题发起人 主题发起人 潘安
  • 开始时间 开始时间

潘安

Unregistered / Unconfirmed
GUEST, unregistred user!
我用webbrowser做一个浏览器,浏览器中的“前进”和“后退”我知道用代码“WEBBROWSER1.GoForward;”,和“ WEBBROWSER1.GoBack;”,但如果我们到了浏览器的最后或者最前页时再按这两个按钮的话运行时就会出错,我知道这两个按钮还有一段判断按钮状态的代码,但不知怎么写。请高手帮帮忙
 
高手们帮帮忙呀
 
处理WebBrowser事件OnCommandStateChange
procedure TForm1.WebBrowserCommandStateChange(Sender: TObject;
Command: Integer; Enable: WordBool);
begin
if Command = CSC_NAVIGATEFORWARD then
begin
//前进按钮.Enabled := Enable;
end else
if Command = CSC_NAVIGATEBACK then
begin
//后退按钮.Enabled := Enable;
end;
end;
 
我那样写了,不行呀,我附上我的全部代码,请帮帮忙:unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, OleCtrls, SHDocVw, StdCtrls, ExtCtrls,
ImgList;


type
TForm1 = class(TForm)
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ImageList1: TImageList;
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
WebBrowser1: TWebBrowser;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure ToolButton8Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton5Click(Sender: TObject);
procedure ToolButton6Click(Sender: TObject);
procedure WebBrowser1DownloadBegin(Sender: TObject);
procedure WebBrowser1DownloadComplete(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure WebBrowser1CommandStateChange(Sender: TObject; Command: Integer; Enable: WordBool);

private

{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
WEBBROWSER1.Navigate(EDIT1.Text);
end;

procedure TForm1.ToolButton8Click(Sender: TObject);
begin
CLOSE;
end;

procedure TForm1.ToolButton2Click(Sender: TObject);
begin
TRY
WEBBROWSER1.GoForward;
EXCEPT
SHOWMESSAGE('已经是最后历史记录.');
EXIT;
end;
END;
procedure TForm1.FormShow(Sender: TObject);
begin
StatusBar1.Panels[1].Text:='当前日期:'+datetostr(date);

end;

procedure TForm1.ToolButton4Click(Sender: TObject);
begin
WEBBROWSER1.Stop;
end;

procedure TForm1.ToolButton1Click(Sender: TObject);
begin
TRY
WEBBROWSER1.GoBack;
EXCEPT
SHOWMESSAGE('已经是到最后历史记录.');
EXIT;
END;
end;

procedure TForm1.ToolButton5Click(Sender: TObject);
begin
WEBBROWSER1.Refresh;
end;

procedure TForm1.ToolButton6Click(Sender: TObject);
begin
WEBBROWSER1.GOHOME;
end;

procedure TForm1.WebBrowser1DownloadBegin(Sender: TObject);
begin
STATUSBAR1.Panels[0].Text:='正在连接地址: '+EDIT1.Text;
end;

procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
STATUSBAR1.Panels[0].Text:='完成: '+WEBBROWSER1.LocationURL;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
Button1Click(Sender);
end;



procedure Tform1.WebBrowser1CommandStateChange(Sender: TObject;
Command: Integer; Enable: WordBool);
begin
case Command of
CSC_NAVIGATEBACK:
begin

ToolButton1.Enabled := enable;
end;
CSC_NAVIGATEFORWARD:
begin
ToolButton2.Enabled := enable;
end;
end;
end;

end.
运行时如果已经是最后或是最前浏览页面时单击“前进”按钮或是“后退”按钮时,会出现“未指定的错误”
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部