Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Navigation with TWebBrowser

Posted on 2002-03-30
6
Medium Priority
?
555 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 200 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
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!

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

705 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