View Issue Details

IDProjectCategoryView StatusLast Update
0021176PatchesLCLpublic2013-09-27 21:14
ReporterEverton Vieira Assigned ToJesus Reyes  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version0.9.30.3 (SVN) 
Fixed in Version1.0.13 (SVN) 
Summary0021176: [Patch] Add InsertRow in TStringGrid
DescriptionHi dear friends, I strongly recommend to add the follow procedure in the class TStringGrid. It has helped me a lot. It's simple and very useful.

It`s my first patch. So take care with it.
Tagsbidi, patch
Fixed in Revision42993
LazTarget1.2
WidgetsetCarbon
Attached Files

Activities

2012-01-27 19:17

 

insertrow.diff (1,250 bytes)   
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 34979)
+++ lcl/grids.pas	(working copy)
@@ -1553,6 +1553,7 @@
       procedure CopyToClipboard(AUseSelection: boolean = false);
       procedure LoadFromCSVFile(AFilename: string; ADelimiter:Char=','; WithHeader:boolean=true);
       procedure SaveToCSVFile(AFileName: string; ADelimiter:Char=','; WithHeader:boolean=true);
+      procedure InsertRow(Index: Integer; Values: array of String; Default: String = '');
       property Cells[ACol, ARow: Integer]: string read GetCells write SetCells;
       property Cols[index: Integer]: TStrings read GetCols write SetCols;
       property DefaultTextStyle;
@@ -10322,7 +10323,20 @@
   end;
 end;
 
+procedure TCustomStringGrid.InsertRow(Index: Integer; Values: array of String; Default: String = '');
+var
+  i1: Integer;
+begin
+  InsertColRow(False, Index);
+  if Length(Values) > ColCount then
+    ColCount := Length(Values);
+  for i1 := 0 to Length(Values) -1 do
+    Cells[i1, Index] := Values[i1];
+  for i1 := Length(Values) to ColCount -1 do
+    Cells[i1, Index] := Default;
+end;
 
+
 procedure Register;
 begin
   RegisterComponents('Additional',[TStringGrid,TDrawGrid]);
insertrow.diff (1,250 bytes)   

Tomasz Wieckowski

2012-01-27 21:17

reporter   ~0056129

What about FixedCols ? your patch always start from col=0 as example goFixedRowNumbering will be broken.
If Default is not set then last loop is redundant.
If InsertRow then InsertCol also should be, or better overloaded InsertColRow.

Everton Vieira

2012-01-28 14:29

reporter   ~0056137

Last edited: 2012-01-28 14:41

You are right about the default. In that case i think the default can be dropped. I'll fix it.

About the FixedCols i think is important to set the value there also.

InsertCol with values make sense?
I don't see the case but if there is then let's do it.

2012-01-28 14:43

 

insertrow-2.diff (1,126 bytes)   
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 34979)
+++ lcl/grids.pas	(working copy)
@@ -1553,6 +1553,7 @@
       procedure CopyToClipboard(AUseSelection: boolean = false);
       procedure LoadFromCSVFile(AFilename: string; ADelimiter:Char=','; WithHeader:boolean=true);
       procedure SaveToCSVFile(AFileName: string; ADelimiter:Char=','; WithHeader:boolean=true);
+      procedure InsertRow(Index: Integer; Values: array of String);
       property Cells[ACol, ARow: Integer]: string read GetCells write SetCells;
       property Cols[index: Integer]: TStrings read GetCols write SetCols;
       property DefaultTextStyle;
@@ -10322,7 +10323,20 @@
   end;
 end;
 
+procedure TCustomStringGrid.InsertRow(Index: Integer; Values: array of String);
+var
+  i1: Integer;
+begin
+  InsertColRow(False, Index);
+  if Length(Values) > ColCount then
+    ColCount := Length(Values);
+  for i1 := 0 to Length(Values) -1 do
+    Cells[i1, Index] := Values[i1];
+end;
 
+
 procedure Register;
 begin
   RegisterComponents('Additional',[TStringGrid,TDrawGrid]);
insertrow-2.diff (1,126 bytes)   

Felipe Monteiro de Carvalho

2012-01-30 10:46

developer   ~0056160

InsertRow might be a confusing name considering that there is InsertColRow with almost the same name and different functionality. I would suggest something longer, maybe: InsertRowWithValues or InsertRowAndFillValues

Everton Vieira

2012-01-30 12:22

reporter   ~0056167

InsertRowWithValues i think is nice.

2012-01-30 12:25

 

insertrow-3.diff (1,146 bytes)   
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 34979)
+++ lcl/grids.pas	(working copy)
@@ -1553,6 +1553,7 @@
       procedure CopyToClipboard(AUseSelection: boolean = false);
       procedure LoadFromCSVFile(AFilename: string; ADelimiter:Char=','; WithHeader:boolean=true);
       procedure SaveToCSVFile(AFileName: string; ADelimiter:Char=','; WithHeader:boolean=true);
+      procedure InsertRowWithValues(Index: Integer; Values: array of String);
       property Cells[ACol, ARow: Integer]: string read GetCells write SetCells;
       property Cols[index: Integer]: TStrings read GetCols write SetCols;
       property DefaultTextStyle;
@@ -10322,7 +10323,20 @@
   end;
 end;
 
+procedure TCustomStringGrid.InsertRowWithValues(Index: Integer; Values: array of String);
+var
+  i1: Integer;
+begin
+  InsertColRow(False, Index);
+  if Length(Values) > ColCount then
+    ColCount := Length(Values);
+  for i1 := 0 to Length(Values) -1 do
+    Cells[i1, Index] := Values[i1];
+end;
 
+
 procedure Register;
 begin
   RegisterComponents('Additional',[TStringGrid,TDrawGrid]);
insertrow-3.diff (1,146 bytes)   

Everton Vieira

2012-01-31 17:28

reporter   ~0056196

Hey, let`s do it. Anyone else think that this is good functionality?

Jesus Reyes

2013-09-27 21:14

developer   ~0070408

Applied, thanks.

Issue History

Date Modified Username Field Change
2012-01-27 19:17 Everton Vieira New Issue
2012-01-27 19:17 Everton Vieira File Added: insertrow.diff
2012-01-27 19:17 Everton Vieira Widgetset => Carbon
2012-01-27 21:17 Tomasz Wieckowski Note Added: 0056129
2012-01-28 14:29 Everton Vieira Note Added: 0056137
2012-01-28 14:33 Everton Vieira Note Edited: 0056137
2012-01-28 14:41 Everton Vieira Note Edited: 0056137
2012-01-28 14:43 Everton Vieira File Added: insertrow-2.diff
2012-01-28 14:50 Everton Vieira Tag Attached: bidi
2012-01-28 14:50 Everton Vieira Tag Attached: patch
2012-01-30 10:46 Felipe Monteiro de Carvalho Note Added: 0056160
2012-01-30 12:22 Everton Vieira Note Added: 0056167
2012-01-30 12:25 Everton Vieira File Added: insertrow-3.diff
2012-01-31 17:28 Everton Vieira Note Added: 0056196
2012-02-01 22:51 Jesus Reyes Status new => assigned
2012-02-01 22:51 Jesus Reyes Assigned To => Jesus Reyes
2012-02-04 10:55 Zeljan Rikalo LazTarget => 1.2
2013-09-27 21:14 Jesus Reyes Fixed in Revision => 42993
2013-09-27 21:14 Jesus Reyes Note Added: 0070408
2013-09-27 21:14 Jesus Reyes Status assigned => resolved
2013-09-27 21:14 Jesus Reyes Fixed in Version => 1.0.13 (SVN)
2013-09-27 21:14 Jesus Reyes Resolution open => fixed