Recent

Author Topic: [Solved] SavetoSpreadSheetFile is crashing  (Read 2777 times)

winni

  • Hero Member
  • *****
  • Posts: 2112
Re: [not totally Solved] SavetoSpreadSheet is crashing
« Reply #30 on: November 29, 2019, 12:20:56 am »
What is the original language of your Operating System??

wp

  • Hero Member
  • *****
  • Posts: 7920
Re: [not totally Solved] SavetoSpreadSheet is crashing
« Reply #31 on: November 29, 2019, 12:30:22 am »
Do you want a copy of such a file that he creates when he has selected the English language option from my app's menu?
Yes please. Since it is a user file you should send it to me personally - you should have received my e-mail address yesterday per PM.

However, I do not believe that this is the issue. Is it for sure that the user gets the same index error that you reported initially and that the crash happened during saving, not after saving and before the program returned back to idle? Can he successfully save the file in the sample test program that I posted above in  Reply #12 of Nov.26? It contains only the saving step. And I already asked for it: what is the exact error message?

You could prepare for him a special version of your program in which you add DebugLn statements to log the points which the program passed successfully (the user should start the program then with command line parameter "--debug-log=name_of_log_file.txt" (without quotes)). Or you could use simple WriteLn statements instead (but don't forget to compile the project with option -WG (or "Project" > "Config and target" > uncheck "Win32  GUI application")).
« Last Edit: November 29, 2019, 12:31:59 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

bobonwhidbey

  • Sr. Member
  • ****
  • Posts: 454
    • Double Dummy Solver - free download
Re: [not totally Solved] SavetoSpreadSheet is crashing
« Reply #32 on: November 29, 2019, 04:42:32 am »
The Op System is Win10 64 bit, using Laz 32 bit - both in English

WP, I sent the XLS file to you 1.5 days ago via email.

It's hard to tell precisely where the crash occurs. I'll try to get a JPG of the error message from the user.

Normally the user clicks a menu option in the app which opens the Print form. The form contains a MainMenu and the tsWorksheetGrid which is Aligned to alClient. In the FromShow the grid is filled with the desired info - shown previously (with some special characters). Clicking the "Copy to XLS File" menu option causes a standard tSaveDialog to get the desired file name. After the file is saved a ShowMessage tells the user the file name that was saved. All really routine stuff. In the Swedish user's situation, the program crashes between returning from the SaveDialog and the ShowMessage.  See below.

Code: Pascal  [Select][+][-]
  1. procedure TPrintForm.CopytoXLSClick(Sender: TObject);
  2. var
  3.   EXT: string;
  4. begin
  5.   SaveDialog1.InitialDir := Opt.FileFolder;
  6.   SaveDialog1.FileName := ChangeFileEXT(INI.MyFileName, '.xls');
  7.   if SaveDialog1.Execute then
  8.   begin
  9.     EXT := uppercase(ExtractFileEXT(SaveDialog1.FileName));
  10.     try
  11.       Grid.SaveToSpreadsheetFile(SaveDialog1.FileName);
  12.       ShowMessage(FastReplace(SB_PBN, 'PBN', EXT)+CRLF+SaveDialog1.FileName);
  13.     except
  14.       on E: Exception do
  15.         ShowMessage('Error raised, with message : ' + E.Message);
  16.     end;
  17.   end;  // if save dialog
  18. end;  

Win10 64-bit / Lazarus 32-bit 2.0.10 / FPC 3.2.0

wp

  • Hero Member
  • *****
  • Posts: 7920
Re: [not totally Solved] SavetoSpreadSheet is crashing
« Reply #33 on: November 29, 2019, 06:20:03 pm »
WP, I sent the XLS file to you 1.5 days ago via email.
Sorry, the mail got caught by the server's spam filter...

The file seems to be written by FPSpreadsheet and, thus, does not contain a COUNTRY record (I never found that it is needed and it is quite difficult in a cross-platform way to determine the country). I do not dare to insert the Swedish record manually because I fear that it may probably destroy the file. I think I'll extend the xls writer to write a COUNTRY record upon request.

As for your code snippet, CopyToXLSClick:

Which Filter options are available in the SaveDialog1? When there are more entries than for xls there is a chance that the user may select a format for which the writer is not in uses -- this would exactly result in the error message that you mentioned in the beginning. So again: please make sure that "fpsallformats" is included in the uses clause of this unit - this makes all file writers available.

If you only want to write an xls file make sure that no other file formats are included in the SaveDialog1.Filter property. In this case, having only "xlsbiff8" in the uses list is fine. (It is not harmful to keep "fpsallformats" - except that reader/writer units are linked in which are not used). You can help the format detection when you mention the xls file format in the Grid.SaveToSpreadsheetFile call:

Code: Pascal  [Select][+][-]
  1.       Grid.SaveToSpreadsheetFile(SaveDialog1.FileName, sfExcel8);
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

bobonwhidbey

  • Sr. Member
  • ****
  • Posts: 454
    • Double Dummy Solver - free download
Re: [not totally Solved] SavetoSpreadSheet is crashing
« Reply #34 on: November 29, 2019, 09:14:19 pm »
All is working well now. As I feared, the problem was all mine. I did not anticipate a Swedish translation being fewer words.   When the app tried to grab the 3rd (non-existent in Swedish) word from a phrase, an Index error was encountered. The user continued beyond the error and thus experienced the crash later on when trying to save the grid to an XLS file.

I want users to be able to save either XLS or ODS files. The program is working perfectly with these files in my Uses statement,
Code: Pascal  [Select][+][-]
  1.  xlsbiff8, xlsxooxml, fpsallformats,
BUT I get a "fpsallformats" not used  hint message after compilation. If I remove that file from Uses, of course the message goes away but I can no longer save ODS files. So - I really do need that fpsallformats file despite the hint.
Win10 64-bit / Lazarus 32-bit 2.0.10 / FPC 3.2.0

wp

  • Hero Member
  • *****
  • Posts: 7920
Re: [Solved] SavetoSpreadSheetFile is crashing
« Reply #35 on: November 29, 2019, 09:32:47 pm »
Good that you found it.

If you only want to save xls, xlsx and ods then "use" xlsbiff8, xlsxooxml and fpsopendocument. See https://wiki.lazarus.freepascal.org/FPSpreadsheet#Workbook -- towards the end of this chapter all the available unit names are listed.

fpsallformats is a dummy unit without any own code. It just puts all the reader/writer units into its uses clause because all these units have some registration code which is executed by the initialization code of each unit. You can safely ignore the "unit not used" warning. Or right-click on this message in the message window and select "Hide message by inserting IDE directive {%H}". Then it won't appear any more.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018