From f7cf091f71319f9d435f275d85c6042e594b01c6 Mon Sep 17 00:00:00 2001 From: bart <9132501-flyingsheep@users.noreply.gitlab.com> Date: Fri, 30 Oct 2020 08:55:51 +0000 Subject: [PATCH] TValueListEditor: disallow having an equal sign ('=') in the Keys column. See https://forum.lazarus.freepascal.org/index.php?topic=51977.0;topicseen git-svn-id: trunk@64089 - --- lcl/valedit.pas | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lcl/valedit.pas b/lcl/valedit.pas index bc6117609e..08bd04ba55 100644 --- a/lcl/valedit.pas +++ b/lcl/valedit.pas @@ -162,6 +162,7 @@ type function GetDefaultEditor(Column: Integer): TWinControl; override; function GetRowCount: Integer; procedure KeyDown(var Key : Word; Shift : TShiftState); override; + procedure KeyPress(var Key: Char); override; procedure LoadContent(cfg: TXMLConfig; Version: Integer); override; procedure ResetDefaultColWidths; override; procedure SaveContent(cfg: TXMLConfig); override; @@ -1315,6 +1316,21 @@ begin if RestoreCurrentRow then Key := 0; end; +procedure TValueListEditor.KeyPress(var Key: Char); +begin + inherited KeyPress(Key); + if (Key = '=') and (Col = 0) then + begin//move to Value column + Key := #0; + //Modified code from TCustomGrid.KeyDown + GridFlags := GridFlags + [gfEditingDone]; + if MoveNextSelectable(True, 1, 0) then + Click; + GridFlags := GridFlags - [gfEditingDone]; + end; +end; + + procedure TValueListEditor.LoadContent(cfg: TXMLConfig; Version: Integer); var ContentSaved, HasColumnTitles, AlwaysShowEditor, HasSaveContent: Boolean; @@ -1455,6 +1471,23 @@ begin if ACol=0 then begin Key := AValue; + { + A Key can never contain an equal sign ('=') + While we disallow typing '=' inside the Key column + we cannot prevent the user from pasting text that contains a '=' + This leads to strange effects since when we insert the Key/Value pair into + the Strings property, in effect the equal sign will be treated (by design) as the separator for the value part. + This in turn updates the Value column, but does not remove the equal sign from Key. + E.g. if both Key and Value celss are empty and you type '=' into an empty Key cell, + the Value cell will become '==' + Reported on forum: https://forum.lazarus.freepascal.org/index.php?topic=51977.0;topicseen + } + if (Pos('=', Key) > 0) then + begin + Key := StringReplace(Key, '=', '', [rfReplaceAll]); + //update the content of the Column cell + inherited SetCells(ACol, ARow, Key); + end; KeyValue := Cells[1,ARow] end else