[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

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!

0
createit
Asked:
createit
1 Solution
 
Russell LibbySoftware 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now