Start a control (twebbrowser) from fresh during runtime

Hi,

I am using a TWebBrowser control. After running my program, I have the twebbrowser control load a web page. Up to here everything is perfect.
After this occurs, somewhere down the line I need to make the twebbrowser control on my form go back to its original state (like how it was when the program was first run). The purpose of this is so that there is no web page associated with it. I do not want there to just be a blank page in it (such as about:blank)...I want it to have no web page associated with it at all.....How could I go about doing this?

Thanks!

createitAsked:
Who is Participating?
 
Russell LibbyConnect With a Mentor Software Engineer, Advisory Commented:
A little trick to access the RecreateWnd procedure of the TWinControl class of the control. First add the following declaration (marked by ---- ADD THIS ---- ) to the unit code (form unit) where the browser control exists.

example:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OleCtrls, SHDocVw;

type
  TForm2 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

// ---- ADD THIS ----
type
  TSuperWinControl =   class(TWinControl);

var
  Form2: TForm2;

implementation
{$R *.DFM}

--------------------------

Then, add the code to call the recreatewnd procedure. This will force delphi to recreate this control which will give you exactly what you are asking for; the control just as it was when first started.

Example:

procedure TForm1.Button2Click(Sender: TObject);
begin

  TSuperWinControl(WebBrowser1).RecreateWnd;

end;


Regards,
Russell

0
 
createitAuthor Commented:
All I can say is....Perfection!

Thank you so much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.