Aspose.Words used in Delphi leads to invalid floating point operation

I have a same Problems like described in this thread: Aspose.Words invoked through COM fails to open some Word templates

Unfortunately the solutions of this thread don’t help in my case.

Here is the code I’m using:

procedure TForm7.Button1Click(Sender: TObject);
var
WordApp, ADoc: OLEvariant;
begin
CoInitialize(nil);
WordApp := CreateOleObject(‘Aspose.Words.ComHelper’);
ADoc := CreateOleObject(‘Aspose.Words.Document’);
try
ADoc := WordApp.Open(‘s:/doc/doc1.docx’);
ADoc.Save(‘s:\doc\doc2.docx’);
finally
CoUninitialize;
end;
end;

And here is the error message I get:
In Project S:.… occured an error with the following message: ‘Floating Point invalid Operation at 0x79aa47a8’. Process stopped…

Does anyone has the same issue or a solution for this Problem?

Hi Andreas,

Can you please share which version of Delphi are you using?

Best Regards,

We tried it with Delphi 2010, XE5 and XE7.

All with the same error.

Hi Andreas,

Thanks for the information. We will test your code on Delphi and let you know.

Best Regards,

Hi Andreas,

Sorry, I was not able to see the issue at my end using the samples I have. Can you please share your sample document to reproduce the issue? This looks like a document specific issue.

Best Regards,

Thanks for testing.



We just used a Word document without any Content. I will add it as attachment.



Here is also the whole Project in Delphi. Maybe it helps:



unit Unit7;



interface



uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Unit26, ComObj, ActiveX;



type

TForm7 = class(TForm)

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private-Deklarationen }

public

{ Public-Deklarationen }

end;



var

Form7: TForm7;



implementation







{$R *.dfm}



procedure TForm7.Button1Click(Sender: TObject);

var

WordApp, ADoc: OLEvariant;

begin

CoInitialize(nil);

WordApp := CreateOleObject(‘Aspose.Words.ComHelper’);

ADoc := CreateOleObject(‘Aspose.Words.Document’);

try

ADoc := WordApp.Open(‘s:/doc/doc1.docx’);

ADoc.Save(‘s:\doc\doc2.docx’);

finally

CoUninitialize;

end;

end;



end.

Hi Andreas,

Thanks for the details. I was able to see the same issue at my end. We are further investigating this issue and will let you know once we have any update. Sorry for the inconvenience.

Best Regards,

Thanks for testing! We are really interested in the results because we want to buy your product.

There are two questions left:

Does Aspose.Words also support pdf/a?
And can I use Aspose.Words within a service?

Hi Andreas,

Yes, Aspose.Words supports PDF/A and it can also be used within a service however further investigation is required for your original issue i.e Document.Save method is throwing exception on saving your documents.

We will keep you updated on this.

Best Regards,

Hi Andreas,

Can you please also contact Delphi team in the meantime as in Delphi some documents do not work however same documents work in other programming languages when used via COM?

Best Regards,

hi,
Seems to have the same problem with a com dll (framework 4.8.1 / aspose.word 23.1) called in a Delphi 10.4 project.
The call of a function raise the exception ‘floating invalid operation’

Please, a idea ?

using Aspose.Words.Replacing;
using Aspose.Words;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;


// signed mdp : diamiccs
// https://blogs.embarcadero.com/using-a-net-assembly-via-com-in-delphi/#Introduction

namespace PilotTest
{
    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    [Guid("5BD21BCE-7CF3-454B-A3E0-D5348F8C6A9B")]
    public interface IPilotTest
    {
        [DispId(1)]
        string wdFileOpen(string pPath);

        [DispId(2)]
        string WdFileNew(string pNomModele, int pNuModele);

        [DispId(3)]
        string WdFileSaveAs(string pPath);

        [DispId(4)]
        string WdFileSaveAsFormat(string pPath, int pFileFormat);

        [DispId(5)]
        string WdFileSaveAsFormat2(string pPath, int pFileFormat);


    }

    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    [Guid("DCCB8C80-9B57-45A9-A35B-DFCEB143FD96")]
    public interface IPilotTestEvents
    {
    }


    #region classe PilotTest

    [ComVisible(true)]
    [Guid("4741BF52-BB0C-4D4D-8806-D0732692B862")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComSourceInterfaces(typeof(IPilotTestEvents))]
    [ProgId("PilotTest")]

    // https://learn.microsoft.com/fr-fr/dotnet/standard/native-interop/qualify-net-types-for-interoperation?source=recommendations
    //https://learn.microsoft.com/fr-fr/dotnet/standard/native-interop/com-callable-wrapper#introducing-the-class-interface
    public class PilotTest : IPilotTest
    {

        string IPilotTest.wdFileOpen(string pPath)
        {
           
            var wDocumentTravail = new Aspose.Words.Document(pPath);

        }

        string IPilotTest.WdFileNew(string pNomModele, int pNuModele)
        {
            return "";
        }

        string IPilotTest.WdFileSaveAs(string pPath)
        {
            return "";
        }


        string IPilotTest.WdFileSaveAsFormat(string pPath, int pFileFormat)
        {
            //FPilotWord.WdFileSaveAsFormat(pPath, pFileFormat);
            return "toto";
        }

        string IPilotTest.WdFileSaveAsFormat2(string pPath, int pFileFormat)
        {
            //FPilotWord.WdFileSaveAsFormat2(pPath, pFileFormat);
            return "";
        }

        #endregion

        #region Constructeur
        public PilotTest()
        {
            // !!!!!
            // Ne rien mettre car on appelle pas de constructeur de dll dans Diamic (logique). On passe ici qu'au niveau du testeur.
            // !!!!!
        }
        #endregion Constructeur

}

@ghislaink Does the problem occur with all document or only with a specific one? If the problem occurs only with a specific document, please attach this document here for testing.
Have you tried opening the document using Aspose.Words provided ComHelper class in your Delphi project?

Hi,

Thanks for the ideas but it is still KO.

  1. I tried with differents files and it is the same problem.
  2. I tried (followin your advice) whith the ComHelper, and it is the same problem.

In the code following, I see well the messages and been stopped by the exception when trying the " comHelper.Open" => “floating point invalid operation”.
In addition, i use a Wpf project, with the same code and the same WinWord files to open and it is ok.

I hope you will able to help me …

// -----------------------------------------------------------------------------------
string IPilotTest.wdFileOpen(string pPath)
{
    System.Windows.Forms.MessageBox.Show(pPath);
    ComHelper comHelper = new ComHelper();
    System.Windows.Forms.MessageBox.Show("comHelper.Open(pPath)");
    var wDocumentTravail = comHelper.Open(pPath);
    System.Windows.Forms.MessageBox.Show("Aspose.Words.DocumentBuilder");

@ghislaink I mean that you can use ComHelper class directly from your Delphi code. Like this (though not sure about Delphi syntax):

helper, doc: OLEvariant;
helper:= CreateOleObject("Aspose.Words.ComHelper");
doc:= helper.Open("C:\\Temp\\in.docx");
doc.Save("C:\\Temp\\out.docx");

I do not think that this is Aspose.Words’ problem, looks like "floating point invalid operation" is a common exception in Delphi.

ok … but open a document with aspose.word is not the purpose of my dev, but the start of more operations on the document : replace text, insert text and image, and so on.

I was expecting doing those things in visual / C#, being able to debug functionnalities before expose them by a dll com used in delphi.

Do you suggest, I can do the same with a OLEVariant object in Delphi ? Please give me few links to get samples. It will be great.

Syncerely

@ghislaink Yes, your approach with COM wrapper is correct and preferred for complex scenarios. I suggested the simple code with OLEVariant object in Delphi just for testing purposes.
Also, have you tried using your COM wrapper class in VB script? Again just for testing purposes, sine I suspect that the mentioned exception is Delphi specific and is not related to Aspose.Words itself.

I have found a similar problem. To resolve it, it was necessary to disable the Floating Point Exceptions by using Set8087CW($133f) or SetExceptionMask(exAllArithmeticExceptions):

procedure TForm1.Button1Click(Sender: TObject);
var
  OldExceptionMask: TArithmeticExceptionMask;
  lHelper: Variant;
  lMessage: Variant;
  lResult: Variant;
begin
  OldExceptionMask := SetExceptionMask(exAllArithmeticExceptions);
  try
    TDirectory.CreateDirectory(edtOutputPath.Text);

    lHelper := CreateOleObject('DDiAsposeHelper.AsposeHelper');

    lHelper.TimeOutInSeconds := -1;
    lMessage := lHelper.OpenMessage(edtFilePath.Text);

    lResult := lMessage.SaveBodyToPDF(edtOutputPath.Text);
    ShowMessage(lResult);
  finally
    SetExceptionMask(OldExceptionMask);
  end;
end;