Jump to content


Photo

I found a bug in TNextGrid.AddRow


  • Please log in to reply
1 reply to this topic

#1 WEI

WEI
  • Members
  • 11 posts

Posted 27 November 2006 - 04:13 AM

HI, Boki

I guess I found a bug in TNextGrid.AddRow:

CODE
    if (GridLinesStyle = lsFramed) and (goGrid in Options) and (RowCount > 1)
    then RefreshRowGrid((RowCount - Count) - 1);


If you add a 20 rows to an empty grid (GridLinesStyle = lsFramed and goGrid = True) by calling AddRow(20), then RefreshRowGrid(-1), which cause List Index out of bounds: -1?

Any ideas how to fix?

Regards,

WEI

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 28 November 2006 - 01:16 AM

Hello,

Open file NxCustomGridControl.pas and change procedure:

procedure TNxCustomGridControl.RefreshRowGrid(const Index: Integer);

into:

CODE
procedure TNxCustomGridControl.RefreshRowGrid(const Index: Integer);
var
  TotalRect: TRect;
begin
  case FGridStyle of
    gsReport: TotalRect := GetRowRect(Index);
    gsSlides: TotalRect := GetSlideRect(Index);
  end;
  TotalRect.Top := TotalRect.Bottom - 1;
  TotalRect.Bottom := TotalRect.Top + GridSpace[lpBottom];
  InvalidateRect(Handle, @TotalRect, False);
end;


open NxGrid.pas and change procedure

procedure TNextGrid.AddRow(Count: Integer = 1);

into

CODE
procedure TNextGrid.AddRow(Count: Integer = 1);
var
  I, J, PrevCount: Integer;
begin
  if (Count < 1) then Exit;
  PrevCount := RowCount;
  FCells.AddRow(Count);

    if goUseDefaultValues in Options then { using default values may slow down adding rows }
  begin
      for I := RowCount - Count to RowCount - 1 do
            for J := 0 to Columns.Count - 1 do
            if Columns[J].DefaultValue <> '' then Cells[J, I] := Columns[J].DefaultValue;
  end;

    if (GridLinesStyle = lsFramed) and (goGrid in Options)
    and (RowCount > 1) and (PrevCount > 0) then RefreshRowGrid(PrevCount - 1);

  RefreshRowGrid(RowCount - 1);
  FLastAddedRow := RowCount - 1;

  { refresh added items }
  if UpdateCount = 0 then RefreshVisibleRows(RowCount - Count, RowCount - 1);

  UpdateVertScrollBar;
end;


regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users