Question

Why doesn't OnRefresh or OnPreRefresh fire BeforeNavigate2 when using this code. According to this it is a bug but how to workaround it in Delphi? I am using EmbeddedWB with IE10.

EmbeddedWB1.Navigate('http://www.stackoverflow.com');
EmbeddedWB1.Refresh; // doesn't fire BeforeNavigate2 
Was it helpful?

Solution

A rather simple solution to a stupid problem.

const
  DLCTL_PRAGMA_NO_CACHE = $00004000;

procedure Refresh(const Sender: TCustomEmbeddedWB);
var
  Flag: OleVariant;
begin
  Flag:=DLCTL_PRAGMA_NO_CACHE;
  Sender.Navigate(Sender.LocationURL,Flag);
end;

procedure EmbeddedWB1Refresh(Sender: TCustomEmbeddedWB; CmdID: Integer;
  var Cancel: Boolean);
begin
  Cancel:=True;
  Refresh(Sender);
end;

OTHER TIPS

Navigate2 is an asynchronous operation. By following it with Refresh, you're not giving the navigation a chance to start and fire BeforeNavigate2 event. Perhaps, you should wait for NavigateComplete2 to get fired, before calling Refresh. What exactly are you trying to achieve? The bug you refer to is not related to your Delphi code, it was specific to .NET and got fixed long ago.

[EDITED]. What I said above was incorrect. It might have been true for IE7, but for IE10, both BeforeNavigate2 and NavigateComplete2 do get fired (once), even if Navigate call is immediately followed with Refresh. However, that doesn't trigger OLECMDID_PREREFRESH or OLECMDID_REFRESH commands to be sent by WebBrowser control to its site COM object. I only saw OLECMDID_PREREFRESH coming through when I manually triggered a refresh via right-click menu (but still no OLECMDID_REFRESH). This has been verified with C++/ATL/VS2012. Unfortunately, this doesn't help to answer why the behavior is different with Delphi.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top