Recent

Author Topic: StringGrid: Clear or Clean?  (Read 3485 times)

simone

  • Hero Member
  • *****
  • Posts: 573
StringGrid: Clear or Clean?
« on: November 18, 2019, 03:44:31 pm »
The question in the subject is a little stupid... I know. I read the following docs:

https://lazarus-ccr.sourceforge.io/docs/lcl/grids/tcustomgrid.clear.html

https://lazarus-ccr.sourceforge.io/docs/lcl/grids/tcustomstringgrid.clean.html

As far as I understand it, they are equivalent, apart from the fact that 'clean' offers more flexibility.

My question arises because in a particular context of my application (i.e. when the cursor blinks
on an editable cell), 'clean' generates a run time error (index out of range), whereas 'clear' does not
create problems.

So I ask you: which one is better to use to empty a StrinGgrid?. Thanks in advance.
« Last Edit: November 18, 2019, 03:46:06 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: StringGrid: Clear or Clean?
« Reply #1 on: November 18, 2019, 04:56:25 pm »
Hi!

clear empties the whole grid and sets RowCount = 0 and ColCount = 0

clean deletes the contens of the whole grid or of a subrange to cells[x,y] = ''

For more sophisticated actions ther are

DeleteColRow
InsertColRow
MoveColRow
ExchangeColRow

To your question:

What do you mean with "empty"?
If you want a blank Grid with no rows and no cells use clear.
If you don't want to change the RowCount and ColCount but to empty the contents then use clean.

Yes, not such a lucky syntax - just one char away…

Winni





simone

  • Hero Member
  • *****
  • Posts: 573
Re: StringGrid: Clear or Clean?
« Reply #2 on: November 18, 2019, 05:27:50 pm »
What do you mean with "empty"?

Natural language is very ambigous!

Your explanation is perfect and clarifies to me why I have a run time error using 'clean'.

Thanks!
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: StringGrid: Clear or Clean?
« Reply #3 on: November 18, 2019, 06:55:17 pm »
The text in the help file has been changed in Laz trunk. It is now:

Quote
Cleans all cells in the grid using the specified CleanOptions

Cleans all cells in the grid subject to the given CleanOptions, optionally specifying a range of cells or a rectangular region. See "TGridZoneSet" for more information.
The cleaning operation does not change the number of rows and columns. It only replaces the cell content by empty strings.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: StringGrid: Clear or Clean?
« Reply #4 on: November 18, 2019, 07:13:05 pm »
Quick reaction!

Thanks!

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: StringGrid: Clear or Clean?
« Reply #5 on: November 18, 2019, 08:09:23 pm »
Quick reaction!
No, this had been changed already in August. I just added another sentence now because I still felt it was a bit unclear.

 

TinyPortal © 2005-2018