0

I recently upgraded my application from Delphi 2007 to Delphi XE8. In couple of forms, Form.showmodel line throws "Floating point division by zero" exception. On those forms there is No arithmetic operations done at all.

I tried executing following code before showmodal which resolved the issue.

  var
  CW, SW: word;

  function GetX87CW: word;
    ASM
    FStCW [Result]
  End;

  Function GetX87SW: word; // Assembler;
    ASM
    FStSW [Result]
  End;

  CW := GetX87CW; SW := GetX87SW;

  ShowMessage(Format('CW = $%4x, SW = $%4x',[CW,SW]));

I haven't saved this code and commented out all code and again recompiled the application which also resolved the issue.

Now I closed Delphi and restarted the XE8 IDE. I opened the project and this issue started appearing again but this time, even though I wrote the above code, it still is throwing exception.

Have any one seen such issue and can someone throw some light on possible cause of such issue ?

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
DivX
  • 103
  • 8
  • You did not put enough information. What is your form doing? Such issue would never appear with plain Delphi app. – Arnaud Bouchez Sep 24 '15 at 07:09
  • Nothing in this form is non standard or COM or even Windows API. It has couple of Tlistview and TADODataset for database access. The very strange part is it works on Delphi 2007 but not on Delphi XE8. – DivX Sep 24 '15 at 09:51
  • no question here without [mcve] – David Heffernan Sep 24 '15 at 11:35
  • @DivX ADO is COM-based. See my answer. – Arnaud Bouchez Sep 24 '15 at 11:44
  • Yes I agree that ADO is COM based but TADODataset on XE8 is written by embarcadero hence I was expecting it to work same as Delphi 2007 since the same project compiled with XE 8 throws this exception. – DivX Sep 25 '15 at 06:30
  • @DivX I guess the problem may come from the OleDB provider itself installed on the PC, not the Delphi version. – Arnaud Bouchez Sep 25 '15 at 10:37
  • Thanks Amaud. If I run application compiled in Delphi XE8, it throws this exception, on the same machine if I run the same source compiled in Delphi 2007, it runs smoothly. This makes me think that the issue might be with Delphi version and not with the oledb provider or ADO. However I am doing further investigation to see what is the root cause. – DivX Sep 25 '15 at 11:52

1 Answers1

0

Are you using COM objects, e.g. calling .Net assemblies? Or OpenGL? Or some OleDB/ADO providers? Any other external .dll? I guess so.

Sounds like this issue. You should try to make external non Delphi call safe, by saving and restoring the FPU exception flags, for each call.

As Ken wrote:

var
  Saved8087CW: Word;
begin
  Saved8087CW := Default8087CW;
  // If you want, disable all fpu exceptions 
  // with the next line.
  Set8087CW($133F);
  DoYourComOperationHere;
  Set8087CW(Saved8087CW);
end;
Community
  • 1
  • 1
Arnaud Bouchez
  • 42,305
  • 3
  • 71
  • 159
  • Although beware that Set8087CW is not threadsafe and so this approach cannot be used if more than one thread calls Set8087CW. – David Heffernan Sep 24 '15 at 14:16
  • Accepting this answer as it solved the problem however I am worried that impact of this issue might be very high since all of my projects uses ADO and changing ADO is not an option for me at this point. This only occurred on couple of forms hence I will do more analysis on why it only occurs of few forms since all of the forms uses ADO. – DivX Sep 25 '15 at 06:56