Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi WebBrowser1NewWindow2 (https://www.delphipraxis.net/60264-webbrowser1newwindow2.html)

alpha1 4. Jan 2006 17:01


WebBrowser1NewWindow2
 
Hello! Why this code doesn`t work? It opens new TabSheet but new page doesn`t load. Only old page on new TabSheet is visible!!... :(

Delphi-Quellcode:
procedure TForm1.WebBrowser1NewWindow2(Sender: TObject;
  var ppDisp: IDispatch; var Cancel: WordBool);
var
  TabSheet: TTabSheet;
  Web: TWebbrowser;
begin
  TabSheet := TTabSheet.Create(Form1.PageControl1);

  with TabSheet do
  begin
    PageControl := Form1.PageControl1;
  end;
  Web := TWebbrowser.CreateParented(TabSheet.Handle);
  TabSheet.InsertControl(Web);
  TWinControl(Web).Align := alClient;
  ppDisp := (PageControl1.ActivePage.Controls[0] as TWebBrowser).DefaultDispatch;
  Web.OnNewWindow2 := Webbrowser1NewWindow2;
  PageControl1.ActivePageIndex := PageControl1.PageCount-1;
end;
And how can make, that different TWebbrowser`s TabSheet`s would be controlled with "Back, Forward, Home, ..." buttons individually? Please help me :wall:

toms 4. Jan 2006 18:11

Re: WebBrowser1NewWindow2
 
hi!

Have a look at my Mini Webbrowser Demo

marabu 4. Jan 2006 18:25

Re: WebBrowser1NewWindow2
 
Hello alpha1,

your code will perform better if you take care of the time you advance the ActivePageIndex. You might as well use the Web variable to retrieve the correct browser interface to return:

Delphi-Quellcode:
procedure TForm1.WebBrowser1NewWindow2(Sender: TObject;
  var ppDisp: IDispatch; var Cancel: WordBool);
var
  TabSheet: TTabSheet;
  Web: TWebbrowser;
begin
  TabSheet := TTabSheet.Create(PageControl1);
  TabSheet.PageControl := PageControl1;
  Web := TWebBrowser.Create(TabSheet);
  // Web := TWebbrowser.CreateParented(TabSheet.Handle);
  TabSheet.InsertControl(Web); // this declares TabSheet Parent
  TWinControl(Web).Align := alClient;
  Web.OnNewWindow2 := Webbrowser1NewWindow2;
  PageControl1.ActivePageIndex := PageControl1.PageCount-1;
  ppDisp := Web.DefaultDispatch;
end;
Happy New Year from marabu

alpha1 4. Jan 2006 18:26

Re: WebBrowser1NewWindow2
 
I have already seen your browser. It`s very cool :thumb: but also enough intricate for me :oops: ...
I would be very grateful to you if you could paste here only those functions which I need, because your code in your browser is confused and i can`t to pick that I exactly need... Thank`s yet again! :cyclops:

alpha1 4. Jan 2006 18:41

Re: WebBrowser1NewWindow2
 
Thank`s marabu for your answer but your corrected cose also won`t work :( :?
Please help me somebody because I have tried all codes in this cool(! :thumb: ) forum and I haven`t found working code :roll:

marabu 4. Jan 2006 19:04

Re: WebBrowser1NewWindow2
 
Alpha1, you have investigated your code well. Besides that one mistake you made there is nothing in it to point fingers to. In fact I just ran the corrected code in a tiny test project and it does what you would expect. If the code fails in your project, chance is you are doing evil things elsewhere. Try to isolate the corrected code I gave you in a test project and see for yourself.

marabu

alpha1 4. Jan 2006 21:17

Re: WebBrowser1NewWindow2
 
Ohh shit (sorry :mrgreen: ) There was so stupid error!! Now browser works great! :angel: Thank`s guys! :dancer2:

alpha1 5. Jan 2006 09:39

Re: WebBrowser1NewWindow2
 
I have new one question :) . This code opens new TabSheet but why there doesn`t create any TWebbrowser in this TabSheet?

Delphi-Quellcode:
procedure TForm1.NewTab;
var
  ts: TTabSheet;
  WB: TWebbrowser;
begin
  // Create a new TabSheet
  ts := TsuiTabSheet.Create(suiPageControl1);
  try
    // Assign TTabSheet Properties
    ts.PageControl := PageControl1;
    ts.Parent := PageControl1;
    ts.PageIndex := PageControl1.ActivePageIndex + 1;

    // Create a TWebbrowser instance
    WB := TWebbrowser.Create(ts);

    // put TWebbrowser on TTabSheet
    TControl(WB).Parent := ts;

    // Assign Webbrowser Properties
    WB.Align := alClient;
    WB.Silent := True;
    WB.Visible := True;

    PageControl1.ActivePage := ts;

    // Assign Webbrowser Events
    WB.OnStatusTextChange := WebBrowser1StatusTextChange;
    WB.OnTitleChange := WebBrowser1TitleChange;
    WB.OnNewWindow2 := WebBrowser1NewWindow2;
    WB.OnCommandStateChange := WebBrowser1CommandStateChange;
    ImageButton1.Enabled := False;
    ImageButton2.Enabled := False;
  except
    ts.Free;
  end;
end;

alpha1 5. Jan 2006 10:02

Re: WebBrowser1NewWindow2
 
I have found new good:

Delphi-Quellcode:
procedure TForm1.NewTab;
var Tab: TTabSheet;
    Browser: TWebBrowser;
begin
 Tab:= TTabSheet.Create(PageControl1);
 Tab.PageControl := PageControl1;
 Tab.Caption := 'about:blank';
 Browser:= TWebBrowser.Create(Tab);
 TControl(Browser).Parent := Tab;
 Browser.Align := alClient;
 Browser.Navigate('about:blank');
end;
It works great :)

toms 5. Jan 2006 10:03

Re: WebBrowser1NewWindow2
 
Liste der Anhänge anzeigen (Anzahl: 1)
The code works fine for me (look at the compiled demo + source in the attachment)


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:14 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz