Recent

Author Topic: TValueListEditor editing behavior  (Read 3005 times)

RubioTerra

  • Newbie
  • Posts: 3
TValueListEditor editing behavior
« on: October 29, 2020, 09:22:18 pm »
I have a TValueListEditor in a form and I'm trying to enter a key on the first column. But whenever I enter an equals sign (=) two equals sign add immediately prepended to the values column. I didn't find any option that would justify this behavior. Is this a bug? I'm using Lazarus v2.0.10.r63526 on Windows 10.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TValueListEditor editing behavior
« Reply #1 on: October 29, 2020, 10:31:56 pm »
That's quite interesting behaviour.
D7 raises an error if you enter an equal sign in the key column.
Please file a bugreport, so it won't be forgotten.
I'll try to fix it when I have the time.

Bart

RubioTerra

  • Newbie
  • Posts: 3
Re: TValueListEditor editing behavior
« Reply #2 on: October 29, 2020, 10:40:59 pm »
Thanks, @Bart. So the correct behavior would be raising an error? This would mean I'm using the component the wrong way. I'm trying to use it to enter pairs of find/replace regexes. I was under the impression that it would support any pair of strings.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TValueListEditor editing behavior
« Reply #3 on: October 29, 2020, 11:40:03 pm »
If you enter the key/values in the grid, you are not supposed to type a '=', just type the key in the left column, the value in the right.
If you want to enter key/value pairs by code, better use the Strings property:
Code: Pascal  [Select][+][-]
  1.   ValueListEditor1.Strings.Add('foo=bar');
Make sure to hide the editor before you do that.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TValueListEditor editing behavior
« Reply #4 on: October 29, 2020, 11:43:35 pm »
So the correct behavior would be raising an error?

D7 does, but I'm inclined not to implement it in that way.
I can suppress typing an equal sign in the Key column (it is allowed and supported in the Value column).
The tricky part is suppressing pasting an equal sign into the Key column.

Also I cannot figure out why pressing '=' behaves like you described: it should never change the Value column.

Bart

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: TValueListEditor editing behavior
« Reply #5 on: October 30, 2020, 03:58:27 am »
It is because default namevalueseparator is equal sign (=) in TStrings (or TStringlist?). If you run following code,

Code: Pascal  [Select][+][-]
  1.     StrLst := TStringList.Create;
  2.     StrList.Values['aname'] := 'AValue';
  3.  
  4.     Showmessage(StrList.Text);
  5.  

This will show
           aname=AValue

Internally Name-value pairs are stored as name=value.

I do not understand why two equal signs are added to the value column, but you can change the NameValueSeparator character to other one which will not be used.

So run following sentence before you 

Code: Pascal  [Select][+][-]
  1.    ValueListEditor1.Strings.NameValueSeparator := '\';
  2.  

And then equal signs will be entered to the key colume in ValueListEditor. 

 

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TValueListEditor editing behavior
« Reply #6 on: October 30, 2020, 10:07:43 am »
I committed a fix in r64089 and r64090.
New behaviour:
If you type '=' (actually: the current NameValueSeparator) in the Keys column, you will be moved to the Value column (as if you had pressed VK_Right).

If you paste an equal sign into the Keys column, this will be removed from the Key value.

I decided NOT to raise an exception for that, because that would require an global exception handler to handle this at the user level.

Please test.

Bart

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: TValueListEditor editing behavior
« Reply #7 on: October 31, 2020, 02:41:30 am »
Quote
I committed a fix in r64089 and r64090.

How can I update the fixes?  --> This is not my main question.

With Lazarus 2.0.10, I still see that when the ValueListEditor is focused and copy strings to the ValueListEditor, i.e.

         ValueListEditor1.Strings.Text := AStringList.Text;

The the first row value is left blank. Is this fixed?

 


dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: TValueListEditor editing behavior
« Reply #8 on: October 31, 2020, 03:19:00 am »
Quote
I committed a fix in r64089 and r64090.

How can I update the fixes?  --> This is not my main question.

With Lazarus 2.0.10, I still see that when the ValueListEditor is focused and copy strings to the ValueListEditor, i.e.

         ValueListEditor1.Strings.Text := AStringList.Text;

The the first row value is left blank. Is this fixed?

what bug report?
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TValueListEditor editing behavior
« Reply #9 on: October 31, 2020, 03:41:00 pm »
Quote
I committed a fix in r64089 and r64090.

How can I update the fixes?  --> This is not my main question.

With Lazarus 2.0.10, I still see that when the ValueListEditor is focused and copy strings to the ValueListEditor, i.e.

         ValueListEditor1.Strings.Text := AStringList.Text;

The the first row value is left blank. Is this fixed?

how about just implementing the KeyDown event and detect for a  "=" as you are typing ? when found, reject the key and move the focus over to the VALUE column .
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: TValueListEditor editing behavior
« Reply #10 on: October 31, 2020, 04:05:20 pm »
And why don't you just press ENTER? This will move the focus into the second column as well. Introducing unconventional keys is really not a good idea.
« Last Edit: October 31, 2020, 04:21:27 pm by wp »

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TValueListEditor editing behavior
« Reply #11 on: October 31, 2020, 04:06:41 pm »
Here is an example for you that works for me  ;)

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ValueListEditor1KeyDown(Sender: TObject; var Key: Word;
  2.   Shift: TShiftState);
  3. begin
  4. if (key = vk_oem_plus)and(not (ssshift in shift)) then with TvalueListEditor(Sender) do
  5.  begin
  6.     col := 1;  // move to the right column of not already there.
  7.     key := 0; //eat the key
  8.  end;
  9. end;                            
  10.  

you could also add some nice back steps here to get back into the key column of you wish by processing the backspace key...
The only true wisdom is knowing you know nothing

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: TValueListEditor editing behavior
« Reply #12 on: October 31, 2020, 04:41:13 pm »
Sorry if my explanations were not sufficient.  Putting equal sign in Key colume is solved, as Bart said. It is related with default NameValueSeparator and programmer should solve it.

My question is not related with the previous issue. When I try to copy the content of other TStrings to TValueListEditor, it is not done  correctly (the first Value is left blank) if the TValueListEditor is focused. I've written this issue at another thread in this forum before, and now I'm asking whether it is solved.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TValueListEditor editing behavior
« Reply #13 on: October 31, 2020, 05:18:11 pm »
Sorry if my explanations were not sufficient.  Putting equal sign in Key colume is solved, as Bart said. It is related with default NameValueSeparator and programmer should solve it.

My question is not related with the previous issue. When I try to copy the content of other TStrings to TValueListEditor, it is not done  correctly (the first Value is left blank) if the TValueListEditor is focused. I've written this issue at another thread in this forum before, and now I'm asking whether it is solved.
I don't know what to tell you ?

I see you demonstrated using a Tstringlist but I am not sure that really is the issue at hand with a valuelist..

 are you having issues with Strniglist or the valueeditor ?
The only true wisdom is knowing you know nothing

bytebites

  • Hero Member
  • *****
  • Posts: 633
Re: TValueListEditor editing behavior
« Reply #14 on: October 31, 2020, 06:36:05 pm »
Does setting valuelist column to zero solve the problem?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   AStringList: TStringList;
  4. begin
  5.   ValueListEditor1.Col:=0;
  6.   AStringList:=TStringList.create;
  7.   AStringList.AddPair('hello','world',nil);
  8.   AStringList.AddPair('moon','shadow',nil);
  9.   ValueListEditor1.Strings.Text := AStringList.Text;
  10. end;
  11.  
  12. procedure TForm1.ValueListEditor1KeyPress(Sender: TObject; var Key: char);
  13. begin
  14.   if key='a' then begin Button1Click(nil);key:=#0;end;
  15. end;
  16.  
  17.  

 

TinyPortal © 2005-2018