View Issue Details

IDProjectCategoryView StatusLast Update
0029842LazarusLCLpublic2016-03-18 06:49
ReporterLagunov AlekseyAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.6.1 (SVN)Product Build51943 
Target Version1.6.2Fixed in Version1.7 (SVN) 
Summary0029842: Error on click to DBGrid after last collumn
DescriptionLazarus 1.7 r51943M FPC 3.1.1 x86_64-linux-gtk 2

After scroll grid cursor to right last collumn and click mouse on empty area after last column - application show error:
Grid index out of range.
Steps To ReproduceIn demo scroll grid cursor to last column CODE - first column ID hide.
after this click to empty area after column CODE.
TagsNo tags attached.
Fixed in Revision51980
LazTarget1.6.2
Widgetset
Attached Files
  • DBGrid_error.zip (130,059 bytes)
  • grids.pas.patch (2,277 bytes)
    Index: grids.pas
    ===================================================================
    --- grids.pas	(revision 51965)
    +++ grids.pas	(working copy)
    @@ -5715,12 +5715,12 @@
       Result:=false;
       with FGCache do begin
         if IsCol then begin
    -      if index>ColCount-1 then
    +      if (index<0) or (index>ColCount-1) then
             exit;
           StartPos:=integer(PtrUInt(AccumWidth[index]));
           Dim:=GetColWidths(index);
         end else begin
    -      if index>RowCount-1 then
    +      if (index<0) or (index>RowCount-1) then
             exit;
           StartPos:=integer(PtrUInt(AccumHeight[index]));
           Dim:= GetRowHeights(index);
    @@ -5807,6 +5807,7 @@
     function TCustomGrid.MouseToGridZone(X, Y: Integer): TGridZone;
     var
       aBorderWidth: Integer;
    +  aCol, aRow: Longint;
     begin
       aBorderWidth := GetBorderWidth;
       if FlipX(X)<FGCache.FixedWidth+aBorderWidth then begin
    @@ -5813,29 +5814,33 @@
         // in fixedwidth zone
         if Y<FGcache.FixedHeight+aBorderWidth then
           Result:= gzFixedCells
    -    else
    -    if (RowCount>FixedRows) and (Y<=FGCache.GridHeight) then
    -      Result:= gzFixedRows
    -    else
    -      Result:= gzInvalid
    +    else begin
    +      OffsetToColRow(False, True, Y, aRow, aCol);
    +      if (aRow<0) or (RowCount<=FixedRows) then
    +        Result := gzInvalid
    +      else
    +        Result := gzFixedRows;
    +    end;
       end
       else if Y<FGCache.FixedHeight+aBorderWidth then begin
         // if fixedheight zone
         if FlipX(X)<FGCache.FixedWidth+aBorderWidth then
           Result:=gzFixedCells
    -    else
    -    if (ColCount>FixedCols) and (FlipX(X)<=FGCache.GridWidth) then
    -      Result:=gzFixedCols
    -    else
    -      Result:=gzInvalid
    +    else begin
    +      OffsetToColRow(True, True, X, aCol, aRow);
    +      if (aCol<0) or (ColCount<=FixedCols) then
    +        Result := gzInvalid
    +      else
    +        Result := gzFixedCols;
    +    end;
       end
       else if not FixedGrid then begin
         // in normal cell zone (though, might be outbounds)
    -    if AllowOutboundEvents or
    -      ((FlipX(X)<=FGCache.GridWidth) and (Y<=FGCache.GridHeight)) then
    -      result := gzNormal
    +    MouseToCell(x, y, aCol, aRow);
    +    if (aCol<0) or (aRow<0) then
    +      result := gzInvalid
         else
    -      result := gzInvalid
    +      result := gzNormal;
       end
       else
         result := gzInvalid;
    
    grids.pas.patch (2,277 bytes)

Activities

Lagunov Aleksey

2016-03-15 08:49

reporter  

DBGrid_error.zip (130,059 bytes)

Jesus Reyes

2016-03-17 08:48

developer  

grids.pas.patch (2,277 bytes)
Index: grids.pas
===================================================================
--- grids.pas	(revision 51965)
+++ grids.pas	(working copy)
@@ -5715,12 +5715,12 @@
   Result:=false;
   with FGCache do begin
     if IsCol then begin
-      if index>ColCount-1 then
+      if (index<0) or (index>ColCount-1) then
         exit;
       StartPos:=integer(PtrUInt(AccumWidth[index]));
       Dim:=GetColWidths(index);
     end else begin
-      if index>RowCount-1 then
+      if (index<0) or (index>RowCount-1) then
         exit;
       StartPos:=integer(PtrUInt(AccumHeight[index]));
       Dim:= GetRowHeights(index);
@@ -5807,6 +5807,7 @@
 function TCustomGrid.MouseToGridZone(X, Y: Integer): TGridZone;
 var
   aBorderWidth: Integer;
+  aCol, aRow: Longint;
 begin
   aBorderWidth := GetBorderWidth;
   if FlipX(X)<FGCache.FixedWidth+aBorderWidth then begin
@@ -5813,29 +5814,33 @@
     // in fixedwidth zone
     if Y<FGcache.FixedHeight+aBorderWidth then
       Result:= gzFixedCells
-    else
-    if (RowCount>FixedRows) and (Y<=FGCache.GridHeight) then
-      Result:= gzFixedRows
-    else
-      Result:= gzInvalid
+    else begin
+      OffsetToColRow(False, True, Y, aRow, aCol);
+      if (aRow<0) or (RowCount<=FixedRows) then
+        Result := gzInvalid
+      else
+        Result := gzFixedRows;
+    end;
   end
   else if Y<FGCache.FixedHeight+aBorderWidth then begin
     // if fixedheight zone
     if FlipX(X)<FGCache.FixedWidth+aBorderWidth then
       Result:=gzFixedCells
-    else
-    if (ColCount>FixedCols) and (FlipX(X)<=FGCache.GridWidth) then
-      Result:=gzFixedCols
-    else
-      Result:=gzInvalid
+    else begin
+      OffsetToColRow(True, True, X, aCol, aRow);
+      if (aCol<0) or (ColCount<=FixedCols) then
+        Result := gzInvalid
+      else
+        Result := gzFixedCols;
+    end;
   end
   else if not FixedGrid then begin
     // in normal cell zone (though, might be outbounds)
-    if AllowOutboundEvents or
-      ((FlipX(X)<=FGCache.GridWidth) and (Y<=FGCache.GridHeight)) then
-      result := gzNormal
+    MouseToCell(x, y, aCol, aRow);
+    if (aCol<0) or (aRow<0) then
+      result := gzInvalid
     else
-      result := gzInvalid
+      result := gzNormal;
   end
   else
     result := gzInvalid;
grids.pas.patch (2,277 bytes)

Jesus Reyes

2016-03-17 08:49

developer   ~0091147

Please try the attached patch

Lagunov Aleksey

2016-03-17 09:35

reporter   ~0091148

work normal.

Issue History

Date Modified Username Field Change
2016-03-15 08:49 Lagunov Aleksey New Issue
2016-03-15 08:49 Lagunov Aleksey File Added: DBGrid_error.zip
2016-03-17 08:48 Jesus Reyes Assigned To => Jesus Reyes
2016-03-17 08:48 Jesus Reyes Status new => assigned
2016-03-17 08:48 Jesus Reyes File Added: grids.pas.patch
2016-03-17 08:49 Jesus Reyes Note Added: 0091147
2016-03-17 09:35 Lagunov Aleksey Note Added: 0091148
2016-03-17 22:17 Jesus Reyes Fixed in Revision => 51980
2016-03-17 22:17 Jesus Reyes LazTarget => 1.6.2
2016-03-17 22:17 Jesus Reyes Status assigned => resolved
2016-03-17 22:17 Jesus Reyes Fixed in Version => 1.7 (SVN)
2016-03-17 22:17 Jesus Reyes Resolution open => fixed
2016-03-17 22:17 Jesus Reyes Target Version => 1.6.2
2016-03-18 06:49 Lagunov Aleksey Status resolved => closed