Page 1 of 2
"floating point division by zero" with AutoWidthCols
Posted: Mon Jan 13, 2014 7:01 pm
by andre.santos
Hi
When i use the AutoWidthCols(), this function be return a error - "floating point division by zero" .
In old version worked perfectly, but after update the component this problem has happened.
Re: "floating point division by zero" with AutoWidthCols
Posted: Tue Jan 14, 2014 4:28 pm
by adrianosilva
Hello,
I updated to the latest version and got the same error.
Re: "floating point division by zero" with AutoWidthCols
Posted: Wed Jan 15, 2014 1:07 pm
by larsa
Hello
I can't reproduce this. Tested with update 5.20.11
It the error persists, please provide a complete sample that reproduces the error.
Re: "floating point division by zero" with AutoWidthCols
Posted: Wed Jan 15, 2014 1:57 pm
by andre.santos
Hi
I did the sample and the error still persist. This code:
XLS.Clear();
XLS[0].AsString[0, 0] := 'Testing Value 0';
XLS[0].AsString[0, 1] := 'Testing Value';
XLS[0].AsString[0, 2] := 'Testing';
XLS[0].AsString[0, 3] := 'Testing Value 0 Testing Value 0 Testing Value 0';
XLS[0].AsString[1, 0] := 'Testing';
XLS[0].AsString[1, 1] := 'Testing Value 0 Testing Value 0 Testing Value 0';
XLS[0].AsString[1, 2] := 'Testing';
XLS[0].AsString[1, 3] := 'Testing Value';
XLS[0].AutoWidthCols(0, 1);
XLS[0].Name := 'Teste';
XLS.Filename := 'C:\Test.xlsx';
XLS.Write;
I am using the latest version.
Re: "floating point division by zero" with AutoWidthCols
Posted: Wed Jan 15, 2014 2:38 pm
by larsa
Hello
Still no luck. Which Delphi version do you use?
Re: "floating point division by zero" with AutoWidthCols
Posted: Wed Jan 15, 2014 3:09 pm
by andre.santos
Hi,
i´m using Delphi XE2
Re: "floating point division by zero" with AutoWidthCols
Posted: Wed Jan 15, 2014 3:32 pm
by andre.santos
Hi
when I was debugging the code of component, i found this code in 'XLSColumn5.pas'
//XLSColumn5.pas
procedure TXLSColumn.SetPixelWidth(const AValue: integer);
begin
SetWidth(Round(Trunc((AValue - 5) / FOwner.FStyles.StdFontWidth * 100 + 0.5) / 100) * 256);
end;
the value of StdFontWidth is ZERO, returning the error message.
continuing debug the code, i found in 'Xc12DataStyleSheet5.pas', this code:
{$ifdef XLS_XSS}
procedure TXc12Fonts.CalcStdFontWidthHeight;
var
i: integer;
S: AxUCString;
Sz: TSize;
DC: HDC;
begin
FStdFontWidth := 0;
DC := CreateIC('DISPLAY',Nil,Nil,Nil);
try
SelectObject(DC,Items[0].GetHandle(GetDeviceCaps(DC,LOGPIXELSY)));
for i := 1 to 10 do begin
S := StrDigits;
Windows.GetTextExtentPoint32W(DC,PWideChar(S),1,Sz);
if Sz.cx > FStdFontWidth then
FStdFontWidth := Sz.cx;
end;
FStdFontHeight := Items[0].FLF.lfHeight;
finally
DeleteDC(DC);
end;
end;
{$endif}
Here FStdFontWidth receives a value, but when the application is running this code not executed.
In none moment the directive XLS_XSS is defined, so this code came be ignored.
Re: "floating point division by zero" with AutoWidthCols
Posted: Thu Jan 16, 2014 10:20 am
by adrianosilva
Hello,
I'm using Delphi 7 and XLSReadWriteII 5.20.11.
Code below:
sFileName := ExtractFilePath(Application.ExeName) + '\TestXLS.xlsx';
sMsg := '';
Try
xlsWorkbook.Clear;
xlsWorkbook.Version := xvExcel2007;
xlsWorkbook.Filename := sFileName;
xlsWorkSheet := xlsWorkbook.Sheets[0];
xlsWorkSheet.AsString[0, 0] := 'Value';
xlsWorkSheet.AsString[1, 0] := 'Formula';
xlsWorkSheet.AsString[2, 0] := 'Result';
xlsWorkSheet.AutoWidthCols(0, 2); // Here is when the error occurs
xlsWorkbook.Write;
Except
on E : Exception do
begin
MessageBox(Application.Handle, PChar(E.Message + ' - ' + sMsg), 'TestXLS', MB_OK + MB_ICONERROR);
end;
end;
Re: "floating point division by zero" with AutoWidthCols
Posted: Fri Jan 17, 2014 7:36 am
by larsa
Hello
Working fine with D7 as well. The latest update is 5.20.12. Please try that.
Re: "floating point division by zero" with AutoWidthCols
Posted: Fri Jan 17, 2014 5:05 pm
by andre.santos
Hello
I updated to the latest version (5.20.12), but the same error still persist.
I use delphi XE2
Re: "floating point division by zero" with AutoWidthCols
Posted: Fri Jan 17, 2014 9:00 pm
by rjvanvliet
I got the same problem with Delphi Xe5.
Also the same error when inserting an image.
Regards,
RJvV
Re: "floating point division by zero" with AutoWidthCols
Posted: Mon Jan 20, 2014 4:33 pm
by CareAll
Same with Delphi 7.
Re: "floating point division by zero" with AutoWidthCols
Posted: Tue Jan 21, 2014 2:48 pm
by larsa
Hello
As I can't reproduce this error and hence debug the code, please check where/what in the source code that it is that causes this.
Re: "floating point division by zero" with AutoWidthCols
Posted: Tue Jan 21, 2014 9:17 pm
by rjvanvliet
Hello,
I downloaded the latest version and removed all xlsread*.* files after deinstallation. Then I installed version 5.20.13 and now auto width and images word fine again. it must be some old source in my debug/ release dir. Strange but it works for me. So happy again!!
Regards,
RJ
Re: "floating point division by zero" with AutoWidthCols
Posted: Wed Jan 22, 2014 1:21 pm
by adrianosilva
Hello,
The error occurs on file XLSColumn5.pas, line 328, in the procedure below:
procedure TXLSColumn.SetPixelWidth(const AValue: integer);
begin
SetWidth(Round(Trunc((AValue - 5) / FOwner.FStyles.StdFontWidth * 100 + 0.5) / 100) * 256);
end;
AValue has a integer value greater than 0 and FOwner.FStyles.StdFontWidth value is 0.