Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delphi 2009 TwebBrowser new window

Status
Not open for further replies.

chris348

Programmer
May 3, 2010
3
0
0
GB
Have used the TWebBrowser component OK, except that when a pop up window appears, it is opened in Internet Explorer. Would be grateful for advice on how to get it to open as a TWebBrowser window. Have struggled for a while on this. Delphi version is 2009. Thanks in advance.
 
you must implement the newwindow2 event.
typically you will have a form that you create on the fly and bind the TWebbrowser.Application object to ppDisp (see last line code sample)

Code:
procedure TFrm_browser.BrowserNewWindow2(ASender: TObject; var ppDisp: IDispatch; var Cancel: WordBool);

var Rect : TRect;

begin
 // Only allow 1 popup
 if Assigned(Popup) then
  begin
   Popup.Close;
   FreeAndNil(Popup);
  end;
 Popup := TFrm_browser.Create(Self, True, Debug, Handle, Rect);
 Popup.Caption := Self.Caption + ' (popup)';
 ppDisp := Popup.Browser.Application;
end;

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Daddy,

Many thanks for the reply. Problem now is that the message appears - Undeclared identifier 'Popup'.

Chris
 
I provided just a code sample, not a quick copy & paste solution.

To recap: you have a form with a TWebbrowser component.
in the 'NewWindow2' event of the TWebbrowser component you create a NEW form with a TWebbrowser component and you link the 2 components via the Application property of the TWebbrowser.

In the code sample I provided, that NEW form is stored in a public variable Popup of the calling form.

you can find more info about TWebBrowser events here:


/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Problem now sorted as below.

Code:
procedure TForm7.wb2NewWindow2(ASender: TObject; var ppDisp: IDispatch;
  var Cancel: WordBool);

var Popup: TForm7;

begin
// a new instance of TForm7 will be created
Popup := TForm7.Create(self);
Popup.Caption := 'Required Caption';
Popup.Show;
ppDisp := Popup.wb2.DefaultDispatch;
end;

Thanks for the help.

Chris

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top