Recent

Author Topic: TValueListEditor - index consistency  (Read 2795 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1273
TValueListEditor - index consistency
« 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?


HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: TValueListEditor - index consistency
« Reply #1 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

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: TValueListEditor - index consistency
« Reply #2 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.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TValueListEditor - index consistency
« Reply #3 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

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: TValueListEditor - index consistency
« Reply #4 on: May 17, 2018, 07:40:40 pm »
How does Delphi behave in this case?
The same. From Docs
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.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: TValueListEditor - index consistency
« Reply #5 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.
« Last Edit: May 17, 2018, 08:10:27 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: TValueListEditor - index consistency
« Reply #6 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';

RobbieL91

  • Newbie
  • Posts: 3
Re: TValueListEditor - index consistency
« Reply #7 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 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?

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: TValueListEditor - index consistency
« Reply #8 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