7

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.

3
  • 1
    Not really an answer to your question, but why would you use TWebBrowser if you are not using it for display? Wouldn't be better to just get it using a HTTP Client component like Indy's TIdHTTP or the WinInet API that uses the same settings as IE. See stackoverflow.com/questions/1823542/… Commented Dec 27, 2009 at 11:36
  • 1
    I've used TidHTTP and TidCokkieManager but problems with cookies persist so I saw TWebBrowser like a solution but after tests it has same problem. Commented Dec 27, 2009 at 16:26
  • So what is the question? Is it about the cookies or the event? Maybe it is best if you separate both questions. Commented Dec 27, 2009 at 18:26

5 Answers 5

9
TWinControl(FWebBrowser).Parent := Form1;  // Parent property is read-only unless cast
Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

2

Call for the OnDocumentComplete Problem:

WebBrowser1.HandleNeeded;

or in your case:

FWebBrowser.HandleNeeded;

before webBrowser.Navigate

Comments

1

A component working perfectly with web-pages cookies is TEmbeddedWB from EmbeddedWB and is free.

2 Comments

I cant access EmbeddedWB website for long time. I have the sources and Im using in Delphi 2010, also I have improved some parts and fixed some bugs.
For the "latest" downloads see Wayback's archive, since the website ceased to exist after 2009-04.
1
procedure TForm1.ReCreateBrowser();
begin
    if(WebBrowser <> NIL) then
    begin
       WebBrowser.Stop;
       WebBrowser.Destroy;
    end;

    WebBrowser        := TWebBrowser.Create(Form1);
    TWinControl(WebBrowser).Name   := 'WebBrowser';
    TWinControl(WebBrowser).Parent := Form1; //set parent...can be panel, tabs etc
    WebBrowser.Silent := true;  //don't show JS errors
    WebBrowser.Visible:= true;  //visible...by default true

    //don't set width/heigh/top/left before TWinControl(WebBrowser).Parent := Form1;
    WebBrowser.Top    := 10;
    WebBrowser.Left   := 10;
    WebBrowser.Height := 600;
    WebBrowser.Width  := 800;
    WebBrowser.OnDocumentComplete  := WebBrowserDocumentComplete;
  //WebBrowser.OnNavigateComplete2 := WebBrowserNavigateComplete2;
end;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.