Lazarus

Programming => General => Topic started by: egsuh on May 17, 2018, 11:15:06 am

Title: TValueListEditor - index consistency
Post by: egsuh on May 17, 2018, 11:15:06 am
I'm not sure this is an error or deliberate result.
TValueListEditor.Keys[0] is for the title row. But if I try to get value of n-th (exc. title row) row, then I have to use index of n-1.

That is, following codes result in what I intend ('First key=First Value').

var
    vle: TValueListEditor;

begin
    vle.Keys[1] := 'First key';
    vle.Strings.ValueFromIndex[0] := 'First Value';
end;

Is this intended or a kind of bug?

Title: Re: TValueListEditor - index consistency
Post by: HeavyUser on May 17, 2018, 11:39:48 am
looks like a bug to me the indexing must be the same for both keys and values
Title: Re: TValueListEditor - index consistency
Post by: ASerge on May 17, 2018, 04:54:53 pm
Is this intended or a kind of bug?
This is not a bug. Remove the value of doColumnTitles in DisplayOptions, then you can index Keys from zero.
Title: Re: TValueListEditor - index consistency
Post by: Bart on May 17, 2018, 07:32:30 pm
How does Delphi behave in this case?
If it's not Delphi compatible then please report it in the bugtracker (with a sample application that demonstrates the error).

Bart
Title: Re: TValueListEditor - index consistency
Post by: ASerge on May 17, 2018, 07:40:40 pm
How does Delphi behave in this case?
The same. From Docs (http://docwiki.embarcadero.com/Libraries/Tokyo/en/Vcl.ValEdit.TValueListEditor.Keys)
Quote
When DisplayOptions includes doColumnTitles, the value of Keys is the title of the first column when Index is 0...When DisplayOptions does not include doColumnTitles, the value of Keys is the Name portion of the string in the specified row
i.e. first row is 1, not zero.
Title: Re: TValueListEditor - index consistency
Post by: taazz on May 17, 2018, 08:08:50 pm
there should not be a difference in the index between key and values regardless of options. If the keys(0) returns the column title then values(0) should return the column title too, it should not in any case return the value of the first cell bellow the title. In the mentioned case it is either a bug or a bad design.
Title: Re: TValueListEditor - index consistency
Post by: ASerge on May 17, 2018, 09:21:23 pm
there should not be a difference in the index between key and values regardless of options. If the keys(0) returns the column title then values(0) should return the column title too, it should not in any case return the value of the first cell bellow the title. In the mentioned case it is either a bug or a bad design.
So historically that the first developers TValueListEditor preferred that the Keys gave access to all cells in Colums[0], not just to the editable elements.
If you want to work only with the edited part, use the syntax for Key=Value pairs:
Code: Pascal  [Select][+][-]
  1. ValueListEditor1.Strings.Strings[0] := 'Key0=';
  2. ValueListEditor1.Strings.ValueFromIndex[0] := 'Value0';
or simple
Code: Pascal  [Select][+][-]
  1. ValueListEditor1.Strings[0] := 'Key0=Value0';
Title: Re: TValueListEditor - index consistency
Post by: RobbieL91 on May 17, 2018, 10:23:12 pm
there should not be a difference in the index between key and values regardless of options. If the keys(0) returns the column title then values(0) should return the column title too, it should not in any case return the Value (https://www.studypug.com/basic-math-help/numbers-and-relations/place-value) of the first cell bellow the title. In the mentioned case it is either a bug or a bad design.
So historically that the first developers TValueListEditor preferred that the Keys gave access to all cells in Colums[0], not just to the editable elements.
If you want to work only with the edited part, use the syntax for Key=Value pairs:
Code: Pascal  [Select][+][-]
  1. ValueListEditor1.Strings.Strings[0] := 'Key0=';
  2. ValueListEditor1.Strings.ValueFromIndex[0] := 'Value0';
or simple
Code: Pascal  [Select][+][-]
  1. ValueListEditor1.Strings[0] := 'Key0=Value0';

What if i want to work with non-edited part?
Title: Re: TValueListEditor - index consistency
Post by: ASerge on May 17, 2018, 11:21:15 pm
What if i want to work with non-edited part?
Many different ways.
Code: Pascal  [Select][+][-]
  1. ValueListEditor1.Keys[0] := '!!!Key';
  2. ValueListEditor1.Cells[1, 0] := '!!!Value';
or
Code: Pascal  [Select][+][-]
  1. ValueListEditor1.TitleCaptions.Append('!!!Key');
  2. ValueListEditor1.TitleCaptions.Append('!!!Value');
TinyPortal © 2005-2018