Lazarus

Programming => LCL => Topic started by: simone on November 18, 2019, 03:44:31 pm

Title: StringGrid: Clear or Clean?
Post by: simone 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.
Title: Re: StringGrid: Clear or Clean?
Post by: winni 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




Title: Re: StringGrid: Clear or Clean?
Post by: simone 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!
Title: Re: StringGrid: Clear or Clean?
Post by: wp 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.
Title: Re: StringGrid: Clear or Clean?
Post by: winni on November 18, 2019, 07:13:05 pm
Quick reaction!

Thanks!
Title: Re: StringGrid: Clear or Clean?
Post by: wp 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