View Issue Details

IDProjectCategoryView StatusLast Update
0030057LazarusLCLpublic2016-04-27 10:22
ReporterwpAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.7 (SVN)Product Build 
Target Version1.8Fixed in Version1.7 (SVN) 
Summary0030057: Grid-save-to-csv issues related to VisibleColumnsOnly
DescriptionTStringGrid's methods SaveToCSVStream/SaveToCSVFile offer the possibility to write its content to a csv stream or file. They have optional parameters WriteTitles and VisibleColumnsOnly. If VisibleColumnsOnly is set to true, however, (it is false by default) and if there is a fixed column the output shows unexpectedly empty cells in place of the fixed column.

This is explained by means of screenshots of a demo project attached to this report. This demo contains a grid at the left; each cell is populated by a string showing the column and row indexes. If the checkbox "Use columns" is checked then the grid is populated in the "column mode", i.e. it creates custom columns. Pressing "Save to streasm & load to memo" saves the grid contents to a memory stream which is read into the memo at the right. The parameters "WriteTitles" and "VisibleColumnsOnly" needed by the grid's SaveToCSVStream method are chosen according to the adjacent checkeboxes named accordingly.

If the VisibleColumnsOnly checkbox is checked, but the WriteTitlesCheckbox not, empty cells at the beginning of each row are written to the stream - see "VisColsOnly.png". The empty cells are "placeholders" for the fixed column cells. The fixed column is expected to be skipped because it is not a "custom" column in the Columns collection.

If WriteTitles is checked additionally then the header of the fixed column is written - it should not be written because the fixed column is not a "custom" column - see "VisColsOnly_WriteTitles.png"

The attached patch fixes the issue and shows the expected behavior, no empty cells and fixed col headers at the left of each line - see "VisColsOnly_WriteTitles-ok.png"
Steps To ReproduceRun attached demo
Make sure to have FixedCols = 1 (or greater)
Check "Use columns" --> the grid is populated in the column mode
Check "Visible columns only"
Press "Save to stream & load to memo" --> the memo shows the written content.
TagsNo tags attached.
Fixed in Revision52253
LazTarget1.8
Widgetset
Attached Files
  • grids.pas.patch (1,316 bytes)
    Index: lcl/grids.pas
    ===================================================================
    --- lcl/grids.pas	(revision 52242)
    +++ lcl/grids.pas	(working copy)
    @@ -11038,11 +11038,14 @@
                 // Collect header column names to a temporary StringList
                 for i := 0 to ColCount-1 do begin
                   c := ColumnFromGridColumn(i);
    -              if c=nil then
    -                HeaderL.Add(Cells[i, 0])
    +              if (c <> nil) then
    +              begin
    +                if c.Visible or not VisibleColumnsOnly then
    +                  HeaderL.Add(c.Title.Caption);
    +              end
                   else
    -                if c.Visible or not VisibleColumnsOnly then
    -                HeaderL.Add(c.Title.Caption);
    +              if not VisibleColumnsOnly then
    +                HeaderL.Add(Cells[i, 0]);
                 end;
                 HeaderL.Delimiter:=ADelimiter;
                 Headerl.StrictDelimiter := False; //force quoting of strings that contain whitespace or Delimiter
    @@ -11063,8 +11066,6 @@
           if Columns.Enabled and VisibleColumnsOnly then begin
             HeaderL := TStringList.Create;
             try
    -        for j := 1 to FixedCols do
    -          HeaderL.Add('');
             for j := 0 to ColCount-1 do begin
               c := ColumnFromGridColumn(j);
               if c=nil then Continue;
    
    grids.pas.patch (1,316 bytes)
  • grid-csv-titles.zip (3,008 bytes)
  • VisColsOnly.png (62,319 bytes)
    VisColsOnly.png (62,319 bytes)

Activities

wp

2016-04-24 17:17

developer  

grids.pas.patch (1,316 bytes)
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 52242)
+++ lcl/grids.pas	(working copy)
@@ -11038,11 +11038,14 @@
             // Collect header column names to a temporary StringList
             for i := 0 to ColCount-1 do begin
               c := ColumnFromGridColumn(i);
-              if c=nil then
-                HeaderL.Add(Cells[i, 0])
+              if (c <> nil) then
+              begin
+                if c.Visible or not VisibleColumnsOnly then
+                  HeaderL.Add(c.Title.Caption);
+              end
               else
-                if c.Visible or not VisibleColumnsOnly then
-                HeaderL.Add(c.Title.Caption);
+              if not VisibleColumnsOnly then
+                HeaderL.Add(Cells[i, 0]);
             end;
             HeaderL.Delimiter:=ADelimiter;
             Headerl.StrictDelimiter := False; //force quoting of strings that contain whitespace or Delimiter
@@ -11063,8 +11066,6 @@
       if Columns.Enabled and VisibleColumnsOnly then begin
         HeaderL := TStringList.Create;
         try
-        for j := 1 to FixedCols do
-          HeaderL.Add('');
         for j := 0 to ColCount-1 do begin
           c := ColumnFromGridColumn(j);
           if c=nil then Continue;
grids.pas.patch (1,316 bytes)

wp

2016-04-24 17:19

developer  

grid-csv-titles.zip (3,008 bytes)

wp

2016-04-24 17:20

developer  

VisColsOnly.png (62,319 bytes)
VisColsOnly.png (62,319 bytes)

wp

2016-04-24 17:20

developer  

wp

2016-04-24 17:21

developer  

Jesus Reyes

2016-04-26 00:02

developer   ~0092225

Applied, thanks.

wp

2016-04-27 10:22

developer   ~0092249

Thanks.

Issue History

Date Modified Username Field Change
2016-04-24 17:17 wp New Issue
2016-04-24 17:17 wp File Added: grids.pas.patch
2016-04-24 17:17 wp Steps to Reproduce Updated View Revisions
2016-04-24 17:19 wp File Added: grid-csv-titles.zip
2016-04-24 17:20 wp File Added: VisColsOnly.png
2016-04-24 17:20 wp File Added: VisColsOnly_WriteTitles.png
2016-04-24 17:21 wp File Added: VisColsOnly_WriteTitles-ok.png
2016-04-24 19:35 Jesus Reyes Assigned To => Jesus Reyes
2016-04-24 19:35 Jesus Reyes Status new => assigned
2016-04-26 00:02 Jesus Reyes Fixed in Revision => 52253
2016-04-26 00:02 Jesus Reyes LazTarget - => 1.8
2016-04-26 00:02 Jesus Reyes Note Added: 0092225
2016-04-26 00:02 Jesus Reyes Status assigned => resolved
2016-04-26 00:02 Jesus Reyes Fixed in Version => 1.7 (SVN)
2016-04-26 00:02 Jesus Reyes Resolution open => fixed
2016-04-26 00:02 Jesus Reyes Target Version => 1.8
2016-04-27 10:22 wp Note Added: 0092249
2016-04-27 10:22 wp Status resolved => closed