Solved

Navigation with TWebBrowser

Posted on 2002-03-30
6
547 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
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 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