Solved

Navigation with TWebBrowser

Posted on 2002-03-30
6
544 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ginsonic
Comment Utility
listening
0
 
LVL 9

Expert Comment

by:ginsonic
Comment Utility
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Richard2000
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for your comment.  I tried redeclaring CSC_UPDATECOMMANDS in Delphi 4 Pro and the compiler warnings disappeared.

Richard
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now