Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using TWebBrowser: forcing Navigation to occur in Same Window

26 views
Skip to first unread message

Bob Dellaca

unread,
Oct 27, 1999, 3:00:00 AM10/27/99
to
The Microsoft Knowledge Base article

HOWTO: Cause Navigation to Occur in Same WebBrowser Window

http://support.microsoft.com/support/kb/articles/q185/5/38.asp

describes how, in VB, to get around a problem with the IE controls
where a WebBrowser object cannot establish the new URL to which the
user is attempting to navigate (TWebBrowser object in Delphi).

The following procedure works with Delphi. It uses an event sink
component imported from the ShDocVw type library with Binh Ly's
EventSinkImp utility:

http://www.intac.com/~bly/com/resources/downloads.htm

(and if you haven't visited the COM pages at Binh Ly's site,
http://www.intac.com/~bly/com , then I can only add my recommendation
to an already long list).

This procedure assumes you have already installed the TWebBrowser
component (import file ShDocVw_TLB.pas), and placed it on a TForm1
form as WebBrowser1.

1. Run EventSinkImp and import the ShDocVw library. The resulting
ShDocVwEvents.pas import file should contain 4 event components.
Adding the import file to the dclusr50.dpk package file (or whatever)
and compiling the package should see the 4 event components installed
on the ActiveX palette tab.

2. Drop a DWebBrowserEvents (*not* DWebBrowserEvents2) component on
the form (as DWebBrowserEvents1 here).

3. Connect the event object to the WebBrowser1 object when the form is
created:

procedure TForm1.FormCreate(Sender: TObject);
begin
try
DWebBrowserEvents1.Connect(WebBrowser1.OleObject);
except
end;
end;

[Disconnect should occur automatially when the event component is
destroyed (i.e. when the form is destroyed).]

4. Ensure that the NewWindow2 event handler (if any) for the
WebBrowser1 object does *not* cancel the operation.

5. Force navigation to occur in the same window, through the NewWindow
event handler for the DWebBrowserEvents1 object:

procedure TForm1.DWebBrowserEvents1NewWindow(Sender: TObject;
const URL: WideString;
Flags: Integer;
const TargetFrameName: WideString;
var PostData: OleVariant;
const Headers: WideString;
var Processed: WordBool);
var
nFlags: OleVariant;
begin
Processed := True;
nFlags := SWC_EXPLORER;
WebBrowser1.Navigate(URL, nFlags);
end;

Bob Dellaca

0 new messages