Главная страница | назад





Article #27726: WebBrowser1.GoBack and WebBrowser1.GoForward creating 'Unspecified error'.

Problem:

Using TWebBrowser GoBack method at the beginning of the history list or using the GoForward method at the end of the history list causes 'Unspecified Error'. According to the Delphi Help "GoBack has no effect unless the history list contains additional documents."


Solution:

This is a documentation error in the Delphi Help. If you look in Microsoft's Platform SDK documentation you will find the following: "if the beginning of the history list has been reached the IWebBrowser2::GoBack method should not be used."

If you want to have a button or similar component that will allow you to GoBack and another button that will let you GoForward using the TWebBrowser component, here is an example of the best way to proceed that will avoid the unspecified error.

In your application drop a TWebBrowser component on the form and two button components. Name the first Button btnBack and the next button btnForward. For both of these buttons, change the enabled property to False. In the OnClick event of btnBack the code should look like this:

procedure TForm1.btnBackClick(Sender: TObject);
begin
WebBrowser1.GoBack;
end;

In the onClick event of btnForward the code will look like this:
procedure TForm1.btnForwardClick(Sender: TObject);
begin
WebBrowser1.GoForward;
end;

These buttons are currently disabled and we only want them enabled when appropriate. To do this we will use the TWebBrowser's OnCommandStateChange event. The code should look like this:
procedure TForm1.WebBrowser1CommandStateChange(Sender: TObject;
Command: Integer; Enable: WordBool);
begin
case Command of
CSC_NAVIGATEBACK: btnBack.Enabled := Enable;
CSC_NAVIGATEFORWARD: btnForward.Enabled := Enable;
end;
end;

This will avoid throwing the "unspecified error".

Last Modified: 16-SEP-01