Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating TWebBrowser in Runtime with Delphi

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.

like image 924
Billiardo Aragorn Avatar asked Dec 27 '09 02:12

Billiardo Aragorn


2 Answers

TWinControl(FWebBrowser).Parent := Form1;  // Parent property is read-only unless cast
like image 89
tomo7 Avatar answered Sep 29 '22 09:09

tomo7


You may have this issue because the TWebBrowser internally works closely together with the handle of the parent form to get messages posted from windows. Try using a hidden form with the TWebBrowser on (optionally run-time created as well), and/or investigate if the HandleAllocated and HandleNeeded methods could help you.

like image 29
Stijn Sanders Avatar answered Sep 29 '22 10:09

Stijn Sanders