Lazarus

Programming => LCL => Topic started by: RubioTerra on October 29, 2020, 09:22:18 pm

Title: TValueListEditor editing behavior
Post by: RubioTerra 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.
Title: Re: TValueListEditor editing behavior
Post by: Bart 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
Title: Re: TValueListEditor editing behavior
Post by: RubioTerra 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.
Title: Re: TValueListEditor editing behavior
Post by: Bart 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
Title: Re: TValueListEditor editing behavior
Post by: Bart 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
Title: Re: TValueListEditor editing behavior
Post by: egsuh 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. 

 
Title: Re: TValueListEditor editing behavior
Post by: Bart 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
Title: Re: TValueListEditor editing behavior
Post by: egsuh 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?

 

Title: Re: TValueListEditor editing behavior
Post by: dsiders 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?
Title: Re: TValueListEditor editing behavior
Post by: jamie 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 .
Title: Re: TValueListEditor editing behavior
Post by: wp 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.
Title: Re: TValueListEditor editing behavior
Post by: jamie 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...
Title: Re: TValueListEditor editing behavior
Post by: egsuh 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.
Title: Re: TValueListEditor editing behavior
Post by: jamie 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 ?
Title: Re: TValueListEditor editing behavior
Post by: bytebites 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.  
Title: Re: TValueListEditor editing behavior
Post by: Bart on October 31, 2020, 07:04:21 pm
Quote
I committed a fix in r64089 and r64090.
How can I update the fixes?  --> This is not my main question.

I did not request this to be merged to the fixes branch.
The new behaviour ('=' -> goto Value column) breaks existing behaviour.
It's more of a new feature than a fix (it's part of the way I implemented the fix though).
The second part of the fix: reverting a pasted '=' is a bit more tricky. I don't know it this (how I did it) is the correct way, so I do not want that merged to fixes. Let it be in trunk for a while.

There is an easy workaround: assign OnKeyPress to the ValueListEditor, suppress '='  if Col equals zero.

Alternatively:
Implement EditorCanAcceptChar for TValueListEditor and do it (suppressing '=') there.

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?

With trunk (and this should also work in current stable) I do
Code: Pascal  [Select][+][-]
  1.     ValEd.Strings.Assign(memo1.lines);
  2.   //ValEd.Strings.Text := Memo1.Text; {behaves exactly the same}

Where the content of Memo1 is:
Code: [Select]
Key0=Value0
Key1=Value1
Key2=Value2

This works as expected.
And IIRC this has worked for a long time.

Bart
Title: Re: TValueListEditor editing behavior
Post by: egsuh on November 01, 2020, 06:02:26 am
Quote
Let it be in trunk for a while.

I do not know what trunk means exactly, but I'll be waiting for later versions which incorporate those changes. Thank you.
Title: Re: TValueListEditor editing behavior
Post by: Bart on November 01, 2020, 12:13:37 pm
I do not know what trunk means exactly

Trunk is the development branch.
Releases are split of from trunk and form a different branch then, so development can go on and only fixes will be merged to the release branch (called fixes branch in our case).

See the Lazarus Devolpment Process (https://wiki.lazarus.freepascal.org/Lazarus_Development_Process) article on the wiki.

Bart
TinyPortal © 2005-2018