Creating TWebBrowser in Runtime with Delphi

Billiardo Aragorn picture Billiardo Aragorn · Dec 27, 2009 · Viewed 10.6k times · Source

I have a TWebBrowser object which is created in runtime and used in background, that is, not visible. The problem is that events like OnDocumentComplete dont work or are not triggered in Delphi2009. Any advice?

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  FWebBrowser:= TWebBrowser.Create(Self);
  FWebBrowser.RegisterAsBrowser:= True;
  FWebBrowser.OnDocumentComplete:= WhenDocIsCompleted;
end;

procedure TfrmMain.WhenDocIsCompleted(ASender: TObject; const pDisp: IDispatch;
  var URL: OleVariant);
begin
  ShowMessage('Doc is completed!');
end;

There is any difference important between Navigate and Navigate2? How can I enable cookies here?

Thanks in advance.

Answer

tomo7 picture tomo7 · Mar 12, 2011
TWinControl(FWebBrowser).Parent := Form1;  // Parent property is read-only unless cast