Recent

Author Topic: Stringgrid InsertRowWithValues: auto add columns?  (Read 15456 times)

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #15 on: December 16, 2018, 02:48:39 pm »
I thought that this is due to the special role that the fixed row plays. But for testing I cannot even set RowCount to 0 while FixedRows is 1. When FixedRows=0 and RowCount=0 I cannot reproduce your observation.

What is your Lazarus version? Mine is trunk, you should at least try v2RC2 - maybe the bug is fixed there already.

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #16 on: December 16, 2018, 02:51:03 pm »
Maybe we should check how TStringGrid behaves in Delphi. Although I'm not a fan of Delphi but ... you know ... maintaining compatibility with Delphi is important.
Nothing to compare with: Delphi's TStringGrid does not have an InsertRowWithValues...

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #17 on: December 16, 2018, 02:51:10 pm »
I cannot reporduce this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button6Click(Sender: TObject);
  2. begin
  3.   Sgrid.RowCount := 0;
  4.   SGrid.InsertRowWithValues(0,['1','2','3'])
  5. end;

This will give me a grid with 1 row, with or without goAlwaysAddRow option.
Tested with trunk, but this code has been unchanged for a while now.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #18 on: December 16, 2018, 02:52:27 pm »
I thought that this is due to the special role that the fixed row plays. But for testing I cannot even set RowCount to 0 while FixedRows is 1.

This is by design.

Bart

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #19 on: December 16, 2018, 02:55:27 pm »
I cannot reporduce this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button6Click(Sender: TObject);
  2. begin
  3.   Sgrid.RowCount := 0;
  4.   SGrid.InsertRowWithValues(0,['1','2','3'])
  5. end;

This will give me a grid with 1 row, with or without goAlwaysAddRow option.
Tested with trunk, but this code has been unchanged for a while now.

Bart
No, this crashes for me with EGridException "FixedRows can't be > RowCount". Just an unchanged StringGrid on a new form.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #20 on: December 16, 2018, 03:02:58 pm »
Sorry, I have FixedRows = 0 set in OI, otherwise the crash is as expected...

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #21 on: December 16, 2018, 03:10:50 pm »
Code: Pascal  [Select][+][-]
  1. procedure TCustomStringGrid.InsertRowWithValues(Index: Integer;
  2.   Values: array of String);
  3. var
  4.   i, OldRC: Integer;
  5. begin
  6.   OldRC := RowCount;
  7.   if Length(Values) > ColCount then
  8.     ColCount := Length(Values);
  9.   InsertColRow(false, Index);
  10.   //if RowCount was 0, then setting ColCount restores RowCount (from FGridPropBackup)
  11.   //which is unwanted here, so reset it (Issue #0026943)
  12.   if (OldRc = 0) then RowCount := 1;
  13.   for i := 0 to Length(Values)-1 do
  14.     Cells[i, Index] := Values[i];
  15. end;

It explicitely sets RowCount to 1 if you start out with a RowCount of zero.
This was at the time of Lazarus 1.4.

Bart

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #22 on: December 16, 2018, 03:55:38 pm »
For me using 1.8.4 it works as it should however, I wonder what would happen if you try to insert a row with more
columns than the grid has ?
 
  Could it be additional columns are being wrapped around to generate an additional row?

 I haven't tested this yet.
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #23 on: December 16, 2018, 04:02:47 pm »
..I wonder what would happen if you try to insert a row with more
columns than the grid has ?

Check the code above, ColCount will be adjusted then...

Bart

chrnobel

  • Sr. Member
  • ****
  • Posts: 283
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #24 on: December 16, 2018, 04:31:32 pm »
Maybe we should check how TStringGrid behaves in Delphi. Although I'm not a fan of Delphi but ... you know ... maintaining compatibility with Delphi is important.
As I see it, it would be better having an AddRowWithValues - that would not break (backward) compatibility with Delphi, but would be a much more intuitive approach.

So regardless of whether the grid is totally empty or not, and regardless of fixed rows, it would always append a row in the bottom of the grid.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #25 on: December 16, 2018, 05:10:39 pm »
Lazarus StringGrid is not compatible with Delphi's.
Not sure how Delphi's is now, but we were way ahead of Delphi with ours, and we're not going to remove everything we have and the don't.

According to Embarcadero they don't have AddRow() or InsertRow() (with or without values) at all?

Bart

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #26 on: December 16, 2018, 05:18:52 pm »
I checked with Delphi 10.2 Community Edition: Their StringGrad has neither an InsertRowWithValues, nor an AddInsertRowWithValues, nor any other Insert or Add related to rows.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Stringgrid InsertRowWithValues: auto add columns?
« Reply #27 on: December 16, 2018, 07:36:52 pm »
Its all done within the COLS/ROWS which are Tstrings where you can insert,add as you do with stringlist.

and I think you can also just set the rows/cols and it will also do the same but be blank

I stand corrected..

you need to set the ROW count to add a new one.but it can be done in Delphi with access to the main string pool..

Edit2:
  I looked at one of my old projects in Delphi, yes I did a hack and wrapped the TStringGrid with another within the app to give
me all that good stuff.. Then I noticed that I created a component of that Grid and had installed it on the ToolBar to make it usable via
the OI..
  Its strange what happens when you get OLD-der
« Last Edit: December 16, 2018, 09:45:09 pm by jamie »
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018