Grids.pas shows error in TCustomStringGrid.InsertRowWithValues
Original Reporter info from Mantis: abtaylr
-
Reporter name: Arlen B Taylor
Original Reporter info from Mantis: abtaylr
- Reporter name: Arlen B Taylor
Description:
This appears to be the same issue as raised in ID 0026943.
This concerns the TStringGrid function InsertRowWithValues [Grids.pas, lines 11681].
My function:
function TFormViewEditCharMatrix.AddCharToList(wnbChar: Integer;
BoolRefreshPos: Boolean): Integer;
var
Style1, Style2, Style3 : string;
R : integer;
begin
R := StrGridMatrix.RowCount + 1;
StrGridMatrix.Columns.Enabled;
if CharMatrix.ChMatrix.ChArr[wnbChar].Style and $01 = 1 then
Style1 := '1' else Style1 := '0';
if CharMatrix.ChMatrix.ChArr[wnbChar].Style and $02 = 2 then
Style2 := '1' else Style2 := '0';
if CharMatrix.ChMatrix.ChArr[wnbChar].Style and $04 = 4 then
Style3 := '1' else Style3 := '0';
StrGridMatrix.InsertRowWithValues(R,[Format(' %.5d', [wnbChar]),
Style1, Style2, Style3]);
....
Result := R;
end;
The error that comes up is: EGridException.Create('Use Columns property to add/remove columns');
No columns are being added, only a row.
Steps to reproduce:
In my program when I get to the line for InsertRowWithValues, it takes me to Grids.pas.
Incrementally going forward takes us to TCustomGrid.GetRowCount: which returns a result of 0, which is correct.
Then to : TCustomGrid.GetColCount: which returns 0, which is correct.
We are next taken to: SetColCount which takes us to GetColumns: TGridColumns which takes us to GetEnabled which returns 0.
Next we go to GetVisibleCount which returns 5, which is correct. Going back to GetEnabled returns true.
Finally we get to SetColCount(AValue) which shows 4 which if we are using 0 based counting is correct, but if 1 based like in GetVisibleCount should be 5.
After the error message shown, we go back to InsertRowWithValues, but no rows are shown in Form.
Additional information:
Grids.pas
[11681]
procedure TCustomStringGrid.InsertRowWithValues(Index: Integer;
Values: array of String);
var
i, OldRC: Integer;
begin
OldRC := RowCount;
if Length(Values) > ColCount then
ColCount := Length(Values);
InsertColRow(false, Index);
//if RowCount was 0, then setting ColCount restores RowCount (from FGridPropBackup)
//which is unwanted here, so reset it (Issue #0026943)
if (OldRc = 0) then RowCount := 1;
for i := 0 to Length(Values)-1 do
Cells[i, Index] := Values[i];
end;
[2538]
function TCustomGrid.GetRowCount: Integer;
begin
Result:=FRows.Count;
end;
[2533]
function TCustomGrid.GetColCount: Integer;
begin
Result:=FCols.Count;
end;
[3031]
procedure TCustomGrid.SetColCount(AValue: Integer);
begin
if Columns.Enabled then
raise EGridException.Create('Use Columns property to add/remove columns');
InternalSetColCount(AValue);
end;
[5536]
function TCustomGrid.GetColumns: TGridColumns;
begin
result := FColumns;
end;
[12726]
function TGridColumns.GetEnabled: Boolean;
begin
result := VisibleCount > 0;
end;
[12736]
function TGridColumns.GetVisibleCount: Integer;
{$ifNdef newcols}
var
i: Integer;
{$endif}
begin
{$ifdef newcols}
result := Count;
{$else}
result := 0;
for i:=0 to Count-1 do
if Items[i].Visible then
inc(result);
{$endif}
end;
[]
procedure TCustomGrid.SetColCount(AValue: Integer);
begin
if Columns.Enabled then
raise EGridException.Create('Use Columns property to add/remove columns');
InternalSetColCount(AValue);
end;
Mantis conversion info:
- Mantis ID: 36067
- OS: Kubuntu
- OS Build: 19.04
- Build: 61796
- Platform: x86_64 linux
- Version: 2.0.2
- Fixed in version: 2.0.6
- Fixed in revision: r61946 (#ed3cfadc)
- Target version: 2.0.6