4

I created a TEventObject to provide OnMouseDown and OnMouseMove events for TWebBrowser. The events work perfectly when moving the mouse and when clicking in the webbrowser, but when I scroll or click the webbrowser's vertical scrollbar a EZeroDivide exception ocurs. EurekaLog reports a EZeroDivide exception in d2d1.dll. I tried to trap the exception but nothing I have tried seems to work:

function TEventObject.Invoke( DispID: integer; const IID: TGUID; LocaleID: integer; Flags: Word; var Params;
  VarResult, ExcepInfo, ArgErr: Pointer ): HResult;
begin
  try
    if ( DispID = DISPID_VALUE ) then
    begin
      if Assigned( FOnEvent ) then
        FOnEvent;
      Result := S_OK;
    end
    else
    begin
      FOnEvent := nil;
      Result := E_NOTIMPL;
    end;
  except
    on EZeroDivide do
    begin
      FOnEvent := nil;
      Result := E_NOTIMPL;
    end;
  end;
end;

My question is can I prevent the exception somehow or can mousedown on the TWebbrowser vertical scrollbar be detected to prevent the exception? This exception is a difficult one for me to solve because I do not know much about TEventObject and I do not understand why the exception only ocurs when clicking or dragging the vertical scrollbar. I can provide more infomation if needed. Compiler: Delphi 2010.

[Edit] See this post: http://www.codenewsfast.com/cnf/article/0/waArticleBookmark.7401953 A very simple demo app is available at: http://dl.dropbox.com/u/2167512/bugs/ie9/ie9_bug.zip

This prevents the bug:

Math.SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,exOverflow, exUnderflow, exPrecision]);
Bill
  • 2,993
  • 5
  • 37
  • 71

1 Answers1

3

try to disable FPU exceptions:

System.Set8087CW($133F);

In the newer versions of Delphi:

Math.SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);
kobik
  • 21,001
  • 4
  • 61
  • 121
  • Thank-you very much. SetExceptionMask prevents the exception... See my edit. Can there be side effects from this? – Bill Jan 04 '12 at 16:37
  • Yeah and all of them in whole application. – TLama Jan 04 '12 at 16:39
  • I had a long [discussion](http://stackoverflow.com/questions/8200581/twebbrowser-crashes-with-embedded-youtube-clips) about this issue. my conclusion is that there are no side effects. – kobik Jan 04 '12 at 16:41
  • @TLama - What do you mean "Yeah and all of them in whole application"... not a good idea to use SetExceptionMask? – Bill Jan 04 '12 at 16:43
  • @Bill, nothing more than if you divide somewhere in your application by 0 you won't get the exception. And that [`KB2488113`](http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=982) update I have already on my computer so nothing is fixed. What to say, just MS :) – TLama Jan 04 '12 at 16:48