View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0036067 | Lazarus | LCL | public | 2019-09-11 20:44 | 2019-09-29 12:36 |
Reporter | Arlen B Taylor | Assigned To | Bart Broersma | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Platform | x86_64 linux | OS | Kubuntu | ||
Product Version | 2.0.2 | ||||
Fixed in Version | 2.0.6 | ||||
Summary | 0036067: Grids.pas shows error in TCustomStringGrid.InsertRowWithValues | ||||
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; | ||||
Tags | No tags attached. | ||||
Fixed in Revision | r61946 | ||||
LazTarget | 2.0.6 | ||||
Widgetset | GTK 2 | ||||
Attached Files |
|
|
|
|
The old issue noted indicates that this was solved for Windows, but I am developing for Linux, so perhaps it only solved the problem for windows. |
|
|
|
If you have Columns in a StringGrid, you can't use InsertRowsWithValues. AFAIK it's by design. |
|
Really?!! Here is code I used in another form in this application using InsertRowsWithValues FileListVideo := FileUtil.FindAllFiles(FilePath, SearchMask, true); if VobProcess.AutoSelectMatchingVobs = true then C := '1' else C := '0'; R := 1; if LeftStr(SearchMask,8) <> 'VIDEO_TS' then begin if LeftStr(SearchMask,4) = 'VTS_' then begin for D := 0 to FileListVideo.Count -1 do begin if FindFirstUtf8(FilePath, faAnyFile and faDirectory, SearchRec1)=0 then begin repeat With SearchRec1 do begin FN := ExtractFileName(FileListVideo.Strings[D]); Ext := SysToUtf8(ExtractFileExt(FN)); K := IntToStr(FileSizeUtf8(FileListVideo.Strings[D])); Case Ext of '.IFO' : StringGridVob.InsertRowWithValues(R,['0',FN, K]); '.VOB' : StringGridVob.InsertRowWithValues(R,[C,FN,K]); '.BUP' : Continue; '.srm' : Continue; '.SRM' : Continue; end; if RightStr(FileListVideo.Strings[D], 4) = '.IFO' then VobProcess.LoadIfo(FileListVideo.Strings[D]); inc(R, 1); end; until FindNextUtf8(SearchRec1) <> 0; end; FindCloseUtf8(SearchRec1); end; end; end; |
|
I seem to have gotten passed the problem by artificially making my rowcount + 2 on the first iteration, then rowcount + 1 thereafter. At least I am not getting that error message any more. I appreciate your review of this issue. |
|
Do you use "custom columns" that is, did you use the Columns property to add columns, instead of setting ColCount for your grid? IIRC when using the Columns property, you cannot set ColCount (which is by design). |
|
@arlen: please test with attached patch "grids.insertrowwithvalues.diff". grids.insertrowwithvalues.diff (851 bytes)
Index: lcl/grids.pas =================================================================== --- lcl/grids.pas (revision 61683) +++ lcl/grids.pas (working copy) @@ -11749,11 +11749,19 @@ procedure TCustomStringGrid.InsertRowWithValues(Index: Integer; Values: array of String); var - i, OldRC: Integer; + i, OldRC, Diff: Integer; begin OldRC := RowCount; - if Length(Values) > ColCount then - ColCount := Length(Values); + Diff := Length(Values) - ColCount; + if Diff > 0 then + begin + if Columns.Enabled then + begin + for i := 1 to Diff do with Columns.Add do Title.Caption := ''; + end + else + ColCount := Length(Values); + end; InsertColRow(false, Index); //if RowCount was 0, then setting ColCount restores RowCount (from FGridPropBackup) //which is unwanted here, so reset it (Issue #0026943) |
|
No feedback. Resolved as proposed. Please test and close if OK or reopen if not fixed. |
Date Modified | Username | Field | Change |
---|---|---|---|
2019-09-11 20:44 | Arlen B Taylor | New Issue | |
2019-09-11 20:44 | Arlen B Taylor | File Added: LocalVariableValues.jpeg | |
2019-09-11 20:44 | Arlen B Taylor | File Added: StringGrid.jpeg | |
2019-09-11 20:44 | Arlen B Taylor | File Added: StringGridErrorMsg.jpeg | |
2019-09-11 20:49 | Arlen B Taylor | Note Added: 0118042 | |
2019-09-11 21:07 | Arlen B Taylor | File Added: SetColCount.jpeg | |
2019-09-11 21:07 | Arlen B Taylor | File Added: GetVisibleCount.jpeg | |
2019-09-11 21:07 | Arlen B Taylor | File Added: GetRowCount.jpeg | |
2019-09-11 22:36 | Bart Broersma | Note Added: 0118044 | |
2019-09-12 01:13 | Arlen B Taylor | File Added: FormVobProcess.jpeg | |
2019-09-12 01:13 | Arlen B Taylor | Note Added: 0118046 | |
2019-09-12 05:30 | Arlen B Taylor | Note Added: 0118047 | |
2019-09-12 18:21 | Bart Broersma | Note Added: 0118051 | |
2019-09-12 19:01 | Bart Broersma | Note Edited: 0118051 | View Revisions |
2019-09-13 18:01 | Bart Broersma | Status | new => feedback |
2019-09-13 18:01 | Bart Broersma | LazTarget | => - |
2019-09-14 19:03 | Bart Broersma | File Added: grids.insertrowwithvalues.diff | |
2019-09-14 19:03 | Bart Broersma | Note Added: 0118079 | |
2019-09-14 19:04 | Bart Broersma | Assigned To | => Bart Broersma |
2019-09-14 19:04 | Bart Broersma | Status | feedback => assigned |
2019-09-14 19:04 | Bart Broersma | Status | assigned => feedback |
2019-09-29 12:36 | Bart Broersma | Status | feedback => resolved |
2019-09-29 12:36 | Bart Broersma | Resolution | open => fixed |
2019-09-29 12:36 | Bart Broersma | Fixed in Version | => 2.0.6 |
2019-09-29 12:36 | Bart Broersma | Fixed in Revision | => r61946 |
2019-09-29 12:36 | Bart Broersma | LazTarget | - => 2.0.6 |
2019-09-29 12:36 | Bart Broersma | Widgetset | GTK 2 => GTK 2 |
2019-09-29 12:36 | Bart Broersma | Note Added: 0118183 |