Recent

Author Topic: Are these two use case surfacing two bugs in TValueListEditor?  (Read 495 times)

EganSolo

  • Full Member
  • ***
  • Posts: 197
Are these two use case surfacing two bugs in TValueListEditor?
« on: February 17, 2021, 07:09:14 am »
Sometimes what I perceive as a bug turns out to be ignorance on my part about the component.
I've been using TValueListEditor quite extensively and I've encountered two use cases that _seem_ to be bugs. I've included a small project to illustrate them. Before I think about logging them as bugs, I wanted your take a look :)

Use Case 1: Order of RowCount := 0 and FixedRows := 0 matters.
Drop a TListViewEditor on a form and rename it to VLE. Drop a button and inside the OnClick event of the button write the following code: Alternatively, you can run the supplied program.
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.btn_BugFixedCountClick(Sender: TObject);
  2. Begin
  3.   With VLE do
  4.   begin
  5.     //If you switch the order of these statements, the bug goes away ...
  6.     RowCount  := 0;
  7.     FixedRows := 0;  //<== Triggers an exception: Item Index out of bound.
  8.   End;
  9. end;
  10.  

The code will raise an exception indicating that the index into the internal TStrings object of TValueListEditor is out of bound (-1). If you reverse these two statements, the exception goes away. Is that by design?

Use Case 2: The disappearing object.

This use case is a bit more aggravating: add some rows to the value list editor and set the object of the first column to an instance of a class (again see the supplied code). Everything runs well.

Now, Call TValueListEditor.InsertRow to insert a row. When you do that, the object of the last populated row vanishes. Please see the associated code.

Am I not using InsertRow the right way?

Thanks for your feedback.

Bart

  • Hero Member
  • *****
  • Posts: 4169
    • Bart en Mariska's Webstek
Re: Are these two use case surfacing two bugs in TValueListEditor?
« Reply #1 on: February 17, 2021, 06:10:35 pm »
In Delphi 7 (not really a new version) RowCount is ReadOnly and there is no property FixedRows...
The Delphi DocWiki also does not mention a FixedRows property and says that RowCount is readonly.

That doesn't mean we cannot have these properties in Lazarus though.

If you do the same in a TStringGrid (rowcount/fixedrows) does it crash as well, or only in TValueListEditor?

Bart

Bart

  • Hero Member
  • *****
  • Posts: 4169
    • Bart en Mariska's Webstek
Re: Are these two use case surfacing two bugs in TValueListEditor?
« Reply #2 on: February 17, 2021, 06:30:04 pm »
Q: when you set RowCount := 0, what tis the value of FixedRows at that time?

If it is > 0, then an exception should be raised.
[ETA]
Implemented in r64605
[/ETA]

Bart
« Last Edit: February 17, 2021, 06:36:47 pm by Bart »

EganSolo

  • Full Member
  • ***
  • Posts: 197
Re: Are these two use case surfacing two bugs in TValueListEditor?
« Reply #3 on: February 18, 2021, 08:21:24 am »
Hi Bart,

Thank you, yes, indeed, when I set RowCount = 0, FixedRows > 0. So before setting RowCount to 0, I need to set FixedRows to 0. God it.
What about the second situation? The disappearing object? Is that a bug?

Thanks!

Bart

  • Hero Member
  • *****
  • Posts: 4169
    • Bart en Mariska's Webstek
Re: Are these two use case surfacing two bugs in TValueListEditor?
« Reply #4 on: February 18, 2021, 06:28:52 pm »
I'm not sure.
The preferred way of adding (in code) key/value pairs and objects is by using the Strings property.
The grid in essence is just the visual representation of the underlying Strings object.
If you alter the Strings property, the grid will be updated accordingly.

TValueListEditor of Lazarus is not one on one compatible with Delphi.
AFAIK Delphi does not have Objects for TValueListEditor at all.
This is because we derive TValueListEditor from TCustomStringGrid, whereas Delphi derives it from TCustomDrawGrid (IIRC).

Is it a bug?
I would call it a design feature.

I documented the curent behaviour on the wiki page.

Bart

EganSolo

  • Full Member
  • ***
  • Posts: 197
Re: Are these two use case surfacing two bugs in TValueListEditor?
« Reply #5 on: February 20, 2021, 07:01:37 am »
Thanks, Bart, that's helpful.
Just to confirm: If I want to insert a new row in TValueListEditor, I should insert the content into TStrings and not use InsertRow? Is that the right approach?

Thanks!

Bart

  • Hero Member
  • *****
  • Posts: 4169
    • Bart en Mariska's Webstek
Re: Are these two use case surfacing two bugs in TValueListEditor?
« Reply #6 on: February 20, 2021, 08:44:28 am »
Using the Strings proprty is the preferred way.
However: when doing so, you must make sure that in the grid, there is no editor active.
InsertRow should work though also.

IMO the whole TValueListEditor is a not very well thought out control.
It inherits lots of methods/properies from TCustomStringGrid (in Delphi: TCustomDrawGrid), so users expect those to work.
This is a PITA since in essence the grid is just a visual representation of the Strings property and keeping that sinchronized with the grid (strings->grid and grid->strings) doesn't play out well in many cases.
In essence it is just a convenient way to display Key/Value pairs.
Everything else is bloat.

Bart

EganSolo

  • Full Member
  • ***
  • Posts: 197
Re: Are these two use case surfacing two bugs in TValueListEditor?
« Reply #7 on: February 23, 2021, 09:36:30 am »
Yeah, I'm learning that as I go. My point, Bart, is that when using InsertRow, if the string list is holding objects, then InsertRow causes the object tied to the row below the insertion point to vanish. It struck me as a bug, which is why I wrote this post.


Bart

  • Hero Member
  • *****
  • Posts: 4169
    • Bart en Mariska's Webstek
Re: Are these two use case surfacing two bugs in TValueListEditor?
« Reply #8 on: February 23, 2021, 01:34:31 pm »
I understand.
At least in a TStringGrid it works as expected.

When I have nothing better to do with my life, I will take a look if it is possible to make Objects[] work in TValueListEditor as weel, but it's not very high on my priority list  O:-)

Bart

 

TinyPortal © 2005-2018