Solved

Navigation with TWebBrowser

Posted on 2002-03-30
6
552 Views
Last Modified: 2010-04-04
Hi,

I am using the TWebBrowser ActiveX control with Delphi 4 Professional.  I have these 4 components on the form...

cmdBack - To navigate back
cmdForward - To navigate forward
cmdClearNavigationHistory - To clear the navigation history, so the user can't go back or forward
WebBrowser - The web browser window itself

Now I have 2 issues...

1) Do you have any code that will enable/disable the cmdBack and cmdForward buttons as appropriate?  If the user can't go back any further the cmdBack button should be disabled.  Likewise if the user can't go forward any further the cmdForward button should be disabled.  I know how to navigate back and forward using methods, but I don't know where the user is in the navigation history in order to determine the Enabled status of the buttons.

2) Do you have any code to clear the navigation history, so the user can't navigate back or forward until they have visited some more URLs?

Thanks in Advance,

Richard
0
Comment
Question by:Richard2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ginsonic
ID: 6908474
listening
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6908478
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6908840
hi,
for navigating you moniter the CommandStateChange event :

procedure TForm1.WebBrowser1CommandStateChange(Sender: TObject;
  Command: Integer; Enable: WordBool);
begin
  case Command of
    CSC_NAVIGATEBACK: BackButton.Enabled := Enable;
    CSC_NAVIGATEFORWARD: ForwardButton.Enabled := Enable;
    CSC_UPDATECOMMANDS: begin
       StopButton.Enabled := WebBrowser1.Busy;
    end;
  end;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then webbrowser1.oleobject.navigate(edit1.text);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//put something in dom to get correct button state
webbrowser1.oleobject.navigate('about:blank');
end;

procedure TForm1.BackButtonClick(Sender: TObject);
begin
webbrowser1.GoBack;
end;

procedure TForm1.ForwardButtonClick(Sender: TObject);
begin
webbrowser1.GoForward;
end;

procedure TForm1.StopButtonClick(Sender: TObject);
begin
webbrowser1.Stop;
end;

for clearing the history this is not so easy so i would go to the site ginsonic mentioned and use there components.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Richard2000
ID: 6913253
Hi,

Thanks for your comments and code.  I tried the above and it works.  The code runs fune, but I get 2 compiler warnings with the line CSC_UPDATECOMMANDS: begin, which are..

Constant expression violates subrange bounds
Case label outside of range of case expression

Is there any way to remove them?

Thanks,

Richard
0
 
LVL 17

Expert Comment

by:inthe
ID: 6913901
hi richard,

Really strange and new one on me.
i spoke to a friend and the problem is different in many versions of delphi where a const in the minus is declared in hex,to fix it you can either redeclare it as
const CSC_UPDATECOMMANDS = -1;
or 16 bits  in d4/5
const CSC_UPDATECOMMANDS = $FFFFFFFFFFFFFFFF;
or for d3:
const CSC_UPDATECOMMANDS = $00000000FFFFFFFF;

ive tested them on d5 and it clears the errors:

procedure TForm1.WebBrowser1CommandStateChange(Sender: TObject;
 Command: Integer; Enable: WordBool);
const CSC_UPDATECOMMANDS = -1;
begin
 case Command of
   CSC_NAVIGATEBACK: BackButton.Enabled := Enable;
   CSC_NAVIGATEFORWARD: ForwardButton.Enabled := Enable;
   CSC_UPDATECOMMANDS:
      StopButton.Enabled := WebBrowser1.Busy;
 end;
end;

well i learnt something today :)
Regards Barry
0
 

Author Comment

by:Richard2000
ID: 6918936
Thanks for your comment.  I tried redeclaring CSC_UPDATECOMMANDS in Delphi 4 Pro and the compiler warnings disappeared.

Richard
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question