StrToDateTime covert error .. lazarus / 49-FPSpreadsheet ---------------------------------------------------------------------- todhuk · 2017-08-06 07:17 In the example: db_Export_Import An error occurred while virtual mode exporting from db to excel. StrToDateTime EConvertError: "г."  is not a valid time ? ---------------------------------------------------------------------- wp · 2017-08-06 09:37 Thanks for reporting, but this report is pretty useless since it does not give instructions how to reproduce the error - the demo offers a lot of parameters. ---------------------------------------------------------------------- todhuk · 2017-08-06 12:13 I mean, the function StrToDateTime returns this error. When for examplе: value = "24.8.2016 г."; lCell.DateTimeValue := StrToDateTime(VarToStr(value), Workbook.FormatSettings); ---------------------------------------------------------------------- wp · 2017-08-06 12:32 Certainly. But I don't know how to reproduce this error because it does not occur here. The demo has a pagecontrol with three pages. On which page does the error occur? How are the controls on that page set when the error happens? What is your OS? Which Lazarus/fpc/fpspreadsheet versions are you using? ---------------------------------------------------------------------- Thaddy · 2017-08-06 12:43 Also note that "r." is afaik not a valid formatsetting for stringtodatetime....... So the error is correct. ---------------------------------------------------------------------- todhuk · 2017-08-06 12:57 Thaddy, You're right. To avoid this date format, I need to set another custom date format when generating the dbf table. I use: FPSpreadsheet 1.8.4; Lazarus 1.8RC3; Win 10, 64 bits ---------------------------------------------------------------------- wp · 2017-08-06 14:30 I still don't know what you are doing. I am a very poor mind-reader... ---------------------------------------------------------------------- todhuk · 2017-08-06 16:58 wp, Explain .. I test the example: db_Export_Import 1. Create a database with random records  When inserting the date fields, they are formatted by default in Bulgarian.  (see my_default_date_format.png) 2. Export database table to spreadsheet file  Now only when option Virtual mode (memory saving) is selected, we have an error.  The error is when we convert the date fields here:  lCell.DateTimeValue := StrToDateTime(VarToStr(value), Workbook.FormatSettings);  (see date_err1.png) ---------------------------------------------------------------------- wp · 2017-08-06 17:19 Still too many options, I don't know where the error happens. Ok, let's do it step by step... You compile and run the demo db_Export_Import.You don't change anything.Page "1-Create database" says "Record count 5000", "Database type dbf". You don't change this?Page "2-Export to spreadsheet": Which file format did you select?If I understand correctly, the error only occurs when "Export methid" is "Virtual mode (memory saving)".Is all this correct? Which unit is raising the error? Can you post a stack trace? This means: When the error happens and the exception dialog comes up click "Break", in Lazarus select "View" > "Debug Windows" > "Call stack". Click "Copy All" and paste the text into your post. Then, setup a new console program and use this code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$mode objfpc}{$H+} uses  fpstypes, fpspreadsheet; var  workbook: TsWorkbook;begin  workbook := TsWorkbook.Create;  WriteLn('workbook.FormatSettings');  WriteLn('  ShortDateFormat: ', workbook.FormatSettings.ShortDateFormat);  WriteLn('  LongDateFormat:  ', workbook.Formatsettings.LongDateFormat);  WriteLn('  ShortTimeFormat: ', workbook.Formatsettings.ShortTimeFormat);  WriteLn('  LongTimeFormat:  ', workbook.FormatSettings.LongTimeFormat);  WriteLn('  DateSeparator:   ', workbook.FormatSettings.DateSeparator);  WriteLn('  TimeSeparator: ', workbook.FormatSettings.TimeSeparator);  workbook.Free;end. Post the output of this program because I would like to know exactly what your format strings look like. ---------------------------------------------------------------------- todhuk · 2017-08-06 17:31 In page 2: No matter what export format I choose. The error is always present and does not depend on the export format. Call Stack #0 fpc_raiseexception at :0 #1 SYSUTILS_$$_STRTOTIME$ANSISTRING$TFORMATSETTINGS$$TDATETIME at :0 #2 SYSUTILS_$$_STRTODATETIME$ANSISTRING$TFORMATSETTINGS$$TDATETIME at :0 #3 WRITEVIRTUALCELLS(0x14f49f0, 0x15b0180, 0x1565c70) at ..\..\source\common\xlscommon.pas:4758 #4 INTERNALWRITETOSTREAM(0x14f49f0, 0x15b0180) at ..\..\source\common\xlsbiff8.pas:2167 #5 WRITETOFILE(0x14f49f0, 0x150f8a8 'D:\w2\LS\fpspreadsheet- 1.8.4\examples\db_import_export\data\people.xls', true, 0) at ..\..\source\common\xlsbiff8.pas:2212 #6 WRITETOFILE(0x151a9d0, 0x150f8a8 'D:\w2\LS\fpspreadsheet- 1.8.4\examples\db_import_export\data\people.xls', 2, true, 0) at ..\..\source\common\fpspreadsheet.pas:8295 #7 WRITETOFILE(0x151a9d0, 0x150f8a8 'D:\w2\LS\fpspreadsheet- 1.8.4\examples\db_import_export\data\people.xls', SFEXCEL8, true, 0) at ..\..\source\common\fpspreadsheet.pas:8267 #8 EXPORTUSINGVIRTUALMODE(0x1517630, 0x150f8a8 'D:\w2\LS\fpspreadsheet -1.8.4\examples\db_import_export\data\people.xls') at main.pas:501 #9 BTNEXPORTCLICK(0x1517630, 0x1523c10) at main.pas:216 ---------------------------------------------------------------------- wp · 2017-08-06 17:54 Is this program working correctly? Please post the output. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$mode objfpc}{$H+} uses  SysUtils; var  s: String;  dt: TDateTime;  fs: TFormatSettings; begin  fs := DefaultFormatSettings;   s := DateTimeToStr(now);  WriteLn(s);  dt := StrToDateTime(s);   WriteLn(fs.ShortDateFormat + ' ' + fs.LongTimeFormat);   s := DateTimeToStr(dt, fs);  WriteLn(s);  dt := StrToDateTime(s, fs);   ReadLn;end. ---------------------------------------------------------------------- todhuk · 2017-08-06 18:03 console program ... var   workbook: TsWorkbook; begin   workbook := TsWorkbook.Create;   WriteLn('workbook.FormatSettings');   WriteLn('  ShortDateFormat: ', workbook.FormatSettings.ShortDateFormat);   WriteLn('  LongDateFormat:  ', workbook.Formatsettings.LongDateFormat);   WriteLn('  ShortTimeFormat: ', workbook.Formatsettings.ShortTimeFormat);   WriteLn('  LongTimeFormat:  ', workbook.FormatSettings.LongTimeFormat);   WriteLn('  DateSeparator:   ', workbook.FormatSettings.DateSeparator);   WriteLn('  TimeSeparator:   ', workbook.FormatSettings.TimeSeparator);   workbook.Free; end. ---------------------------------------------------------------------- todhuk · 2017-08-06 18:09 begin   fs := DefaultFormatSettings;   s := DateTimeToStr(now);   WriteLn(s);   dt := StrToDateTime(s); // --> The same error!   WriteLn(fs.ShortDateFormat + ' ' + fs.LongTimeFormat);   s := DateTimeToStr(dt, fs);   WriteLn(s);   dt := StrToDateTime(s, fs);   ReadLn; end. ---------------------------------------------------------------------- Thaddy · 2017-08-06 18:46 Quote from: todhuk on August 06, 2017, 08:09:58 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   s := DateTimeToStr(now);  WriteLn(s);  dt := StrToDateTime(s); // --> [b]The same error![/b]If that is the case, it is a bug. But I can't reproduce it. The call should evaluate symmetrical. We are still missing a lot of information, like FPC version and Laz version and platform and OS and OS version....to name a few.... ---------------------------------------------------------------------- wp · 2017-08-06 20:22 I can confirm if I add extra characters to the time format string even if they are quoted: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;{$mode objfpc}{$H+} uses  SysUtils;var  s: String;  dt: TDateTime;begin  DefaultFormatSettings.LongTimeFormat := '"xx "hh:nn:ss';   s := TimeToStr(now);     // TimeToStr uses format "tt" which is LongTimeFormat  WriteLn(s);  dt := StrToTime(s);end.   As an alternative, try ScanDateTime from unit DateUtils: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  SysUtils, DateUtils; var  s: String;  dt: TDateTime;begin  DefaultFormatSettings.ShortDateFormat := 'dd.mm.yyyy".r"';  dt := EncodeDate(2017, 12, 12) + 0.5;  s := DateTimeToStr(dt);  WriteLn(s);  dt := ScanDateTime('dd.mm.yyyy.r hh:nn:ss', s);end. ---------------------------------------------------------------------- Almir.Bispo · 2017-08-06 20:38 Try it: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  dt:Tdatetime;begins:= '12/12/2017.r';dt:=StrToDateTime( copy( s,1, length(s)-2 ) ); //like get [12/12/2017].r  (except de '.r') end;