If you create a new form, drop a button, then an edit field, then drop a
CppWebBrowser component ( found on the Internet Page ), and then
double-click on the button to add an OnClick handler.
Here's the code I have to handle the event, and cause the navigation within
the WebBrowser VCL to occur:
if ( Edit1->Text.Length() > 0 ) {
WideString wString(Edit1->Text);
//try {
TVariant flags(0); // 0x00 = None, 0x01 = New Window, 0x02 =
Don't add to history.....
TVariant frame("");
TVariant post("");
TVariant header("");
//CppWebBrowser1->Navigate(BSTR(Edit1->Text), &flags, &frame,
&post, &header);
//CppWebBrowser1->Navigate((BSTR)WideString(Edit1->Text),
&flags, &frame, &post, &header);
CppWebBrowser1->Navigate((BSTR)wString, &flags, &frame, &post,
&header);
//} catch ( EInvalidOp &e ) {
//
//}
}
If you drop this into the event handler, and click Run on the IDE, what you
get is essentially a REALLY rudimentary browser.
If I enter: http://www.slashdot.org NO PROBLEM
If I enter: http://www.coke.com EIvalidOp ( Floating Point
Exception )
So, when I saw the exception I figured, ok, let's add a Try{}Catch{} to it.
Notice I commented that out. Why ? Because no matter if I how I configured
the debugger, it would NEVER return the exception, and in some cases ( run
handled by user application ), the applet stopped running altogether and I
had to "Program Reset" in the debugger.
If you change the navigate call to pass 0x01 in the flag field, it'll
actually invoke IE in a separate and pass it the URL to load. What's ODD, is
that if you load it THIS way, it works, and www.coke.com comes up just fine.
The invalid exception only happens when you're trying to load the URL into
the browser window on your own form. The floating point exception occurs in
MSHTML.dll, for those more curious.
The wild and crazy thing about all this, is that if you create a sample
applet ( the same edit field and button as before ) in VisualStudio.NET,
and then add a reference to SHDOCVW.DLL itself in the toolbox, you can drop
a Browser control into a form ( C#, VB, whatever ).
Configuring that control with the same flag settings as the one I made in
BCB6, and then supplying a practically identical button click handler, as
follows:
if ( Edit1.Text.Length > 0 ) {
System.String wsString = Edit1.Text;
System.Object flags = 0; // 0x00 = None, 0x01 = New Window,
0x02 = Don't add to history.....
System.Object frame = "";
System.Object post = "";
System.Object header ="";
axWebBrowser1.Navigate(wsString, ref flags, ref frame, ref post,
ref header);
}
Guess what....it worked....: http://www.coke.com came up INSIDE the
window I'd dropped on the Form.
I'm wondering if BCBIE60.BPL is handling the conversion of the parameters
correctly. A friend of mine tried this under BCB5 and encountered the same
problems. He's running Windows 2000 and I'm running Windows XP. Has anyone
run across the problem ? Anyone able to give an insight ?
Any help would be greatly appreciated.
> if ( Edit1->Text.Length() > 0 ) {
Use GetTextLen() instead, it is more efficient:
if ( Edit1->GetTextLen() > 0 ) {
> CppWebBrowser1->Navigate((BSTR)wString, &flags, &frame, &post,
> &header);
You don't need to cast to BSTR, WideString already does that automatically.
Also, all of the other parameters are optional, so you can omit them
altogether since you are not providing any values anyway:
CppWebBrowser1->Navigate(wString);
Better if you call Navigate2() instead:
CppWebBrowser1->Navigate(&TVariant(wString));
Gambit
> if ( Edit1->GetTextLen() > 0 ) {
>
> > CppWebBrowser1->Navigate((BSTR)wString, &flags, &frame,
&post,
> > &header);
>
> You don't need to cast to BSTR, WideString already does that
automatically.
> Also, all of the other parameters are optional, so you can omit them
> altogether since you are not providing any values anyway:
>
I know I didn't, but hey...at that point, I was grasping at straws, because
I thought it was me causing the problem.
I know that the other parms were optional, but I figured, hey, I passed them
in the Visual Studio.NET applet, at least let me be thorough and make it as
identical as I can, so I'm not making a mistake that way. ( Nevermind that
if I pass only the first parm and I go to someplace like http://www.mci.com,
that it DOES work ).
> CppWebBrowser1->Navigate(wString);
>
> Better if you call Navigate2() instead:
>
> CppWebBrowser1->Navigate(&TVariant(wString));
>
Hadn't thought of it, but hey, it can't hurt...I'll give it a try and post
my findings....Thanks Remy.
Marcelo
> If you create a new form, drop a button, then an edit field, then drop a
> CppWebBrowser component ( found on the Internet Page ), and then
> double-click on the button to add an OnClick handler.
Then all you have to code is:
CppWebBrowser1->Navigate(WideString(Edit1->Text));
I just wonder why you use all that code for.
Cannot comment on bcb6, but for bcb5 it's all that's needed.
Hans.
It's called "exhausting all possible options".
"Hans Galema" <dontu...@dontusethis.nl> wrote in message
news:4052...@newsgroups.borland.com...
I was curious to see if it even got to where it was going so I added a
simple handler for OnNavigateComplete2().
Well, going to: http://www.mci.com gave me 1 call to the handler (
OnNavigateComplete2 )
However, going to: www.coke.com OnNavigateComplete2() was called twice
( it gets redirected to: www.coke.com/flashIndex1.html )
So I try entering that address manually, and I do get 1 call to the
OnNavigateComplete2(), and just after returning from it, I get the Invalid
Floating Point Exception. I've checked to make sure I've got the latest
Flash Player
( Version 7,0,14,0 ), and I still get the exception. The assembler is view
shows an fild instruction,
convert the integer operand (signed) into extended-real and load it onto the
floating-point stack. I looked at the assembler and the data looks ok..the
FPU stack is empty at the time, so there's space there.
Entering that URL in IE works just fine, so I'm a bit of quandry why loading
it that way would cause this to happen.
Marcelo