export data to libreoffice from an application 64 bits build in delphi

Hello, I’m having trouble to export numbers to libreoffice via uno api.
When a build in delphi an application 32 bits its works fine, but 64 bits the numbers turns all to 0 in libreoffice.

The code:
list:= s1.getCellRangeByPosition(x,y,z,w);
list.NumberFormat:= 4;

Ex: 32bits = 3.456 / 64bits = 0

Does anything change in the API between 32 and 64 bits?

thanks in advance

NumberFormat property is of UNO type long (= 32-bit signed integer). This does not change, regardless of what language or architecture you use. However, the language and architecture may define what you are trying to pass there. Remember, that when you pass anything to UNO, it crosses a boundary of a bridge, where it likely converts to an any - meaning that the type that you pass will be kept, until it arrives on the UNO side, where it will be checked if it matches the API requirements.

If Delphi uses 32 bits for an integer literal in 32-bit architecture, and 64 bits for the same literal on 64-bit architecture, then you will be hit (by Delphi / your usage, not by UNO API “changes”). If so, then you will need to cast to 32-bit integer types when passing to UNO’s long.

Note also, that hardcoding number format numeric values is a bad practice. For a code to take the number format code dynamically, see e.g. How to create a Macro to insert the current date in the current language - #7 by mikekaganski

1 Like

Hello,

Thanks for the tips, in fact the problem was in how Delphi was treating the number.
When passing the number to the setvalue property and not in the numberformat propriety.
Not in this code: list.NumberFormat:= x(integer);
But in this code: Cell.setvalue(data.fields[i].Asfloat);

Findings:
in 32bit architecture everything works to export a float number.: field.assingle, asfloat, ascurrency, asvariant, asextended
in 64bit architecture: only works with field.ascurrency and field.asvariant. In other type castings, 0 always appears in libreoffice as a number formatted as required in numberformat: 0,00.

I chose asvariant, problem solved for now.

Thanks again for the explanation.

Hello, good afternoon, I created a component to work with scalc as if it were a dataset.

You can create a for loop to go through the spreadsheet and use the getValue function to access the positions where you want to get the value. There is a Demo with the project showing how to use it. Look at its source code, you can either load a spreadsheet into it or create one from scratch.

Here is the project on github

Years ago when I still had some capabilities concerning Pascal I tried a kind of cooperation between LibO Calc and Pascal using two dll created with FreePascal/Lazarus.
There wasn’t any real-world usage intended - and the example was only made to run under Win.
Now, I’m afraid, I couldn’t do it again due to age and …
You surely know everything in the field better than I do, but in case you are interested:
dblToBitsAndBack_Apply.ods (56.8 KB)
dblBitWise.pas.fake.odg (1.4 KB)