Solved

Navigation with TWebBrowser

Posted on 2002-03-30
6
553 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Technology Partners: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 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