Recent

Author Topic: [SOLVED] StringGrid.LoadFromCSVFile - spaces causes delimiter when tab (#9) used  (Read 8705 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Hi

I've created a test CSV file and I have set tab as the delimitor instead of the more default comma (,). The file has no column headings. I am reading the file into a StringGrid using

StringGrid.LoadFromCSVFile, #9, false

I have columns in my source file containing filenames and paths that contains spaces. e.g

File 1.doc  C:\Test\Folder1
File2.doc  C:\Test\Another Folder
File3 New.doc  C:\Test\A Third Folder

When the CSV file is opened in LibreOffice Calc, the columns all line up properly by tab space and the spaces between names are ignored, as intended.

However, when my program loads the data into the grid, the values with spaces are being spread between one column and the next. e.g. File 1.doc is split between Col1 and Col2, with 'File' in Col1 and '2.doc' in Col2.

Is anyone else experiencing this or is it just me?

I using 0.9.31, PFC 2.6.0 in Linux
 
Does anyone know if this is a bug and if it is, does anyone know if it's already been fixed in v1.1 of Laz and FPC 2.7.0?
« Last Edit: May 19, 2012, 10:44:26 pm by tedsmith »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
I just made some test and it seems taht space is always accepted as delimiter no matter if ADelimiter is tab, comma or whatever.
I tested with Lazarus 1.1 r37217M FPC 2.5.1 x86_64-linux-qt

IMO this should be reported with some simple demo project + dummy data.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Thanks for testing Blaazan.

I have reported it : http://mantis.freepascal.org/view.php?id=22054

Bart

  • Hero Member
  • *****
  • Posts: 5648
    • Bart en Mariska's Webstek
I attached a possible fix in the bugtracker.
Can you please test it?

Bart

PS. Can someone with appropriate rights in the bugtracker move the issue to Lazarus (currently it is in FPC)?
« Last Edit: May 17, 2012, 09:42:47 am by Bart »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
I tested patch with my very small test file and it seems tabs & spaces are handled correctly now.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Thanks a lot for doing this so quickly!!

I am at work today but will try tonight. To save me some time, can you let me know how I use the path on the bugs site with my current Lazarus and FPC configuration? Do I copy it somewhere, overwrite something, or what? Forgive me - I've never done it before.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
I see you use Laz. 0.9.31. It is SVN (did you compile yourself) ?

Bart's patch:
Code: [Select]
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas (revision 37299)
+++ lcl/grids.pas (working copy)
@@ -10276,6 +10276,7 @@
     if L.Count>0 then begin
 
       SubL.Delimiter:=ADelimiter;
+      SubL.StrictDelimiter := True;
       SubL.DelimitedText:=L[0];
 
       if Columns.Enabled then begin
@@ -10308,6 +10309,7 @@
 
       for i:=StartRow to RowCount-1 do begin
         Rows[i].Delimiter := ADelimiter;
+        Rows[i].StrictDelimiter := True;
         Rows[i].DelimitedText:=L[i-StartRow+j];
       end;
     end;

is against r.37299.
You can get this rev. by
Code: [Select]
svn update --revision 37299
How to apply patch: http://wiki.lazarus.freepascal.org/Creating_A_Patch#Applying_a_patch
Of course, you can add these two lines (StrictDelimetier:=True) manualy to grids.pas, it is easy.
And finally, you have to rebuild your Lazarus.
« Last Edit: May 18, 2012, 08:44:33 pm by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Bart

  • Hero Member
  • *****
  • Posts: 5648
    • Bart en Mariska's Webstek
Fixed in r37318.
Original fix was too simple  :)
I had to manually take care of quoted strings.

Please test.
@tedsmith: if OK, then please close the bugreport.

Bart

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Thanks a lot Bart! I have closed the bug report as requested.

 

TinyPortal © 2005-2018