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 -
This commit is contained in:
bart 2020-10-30 08:55:51 +00:00
parent ba446c3a93
commit f7cf091f71

View File

@ -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