View Issue Details

IDProjectCategoryView StatusLast Update
0030044LazarusLCLpublic2016-07-25 22:38
ReporterAndrey KorolAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version1.8Fixed in Version1.7 (SVN) 
Summary0030044: wrong reaction to pressing the esc key in stringgrid cell editor
DescriptionAs i think, string grid editor bring two wrong result as reaction on pressing ESC-key:
1) it leave new value in cell, but intuitively expected restore old value (like in Excel)
2) this new value not handled by ValidateEntry. If pressed ESC - event OnValidateEntry is not executed

I propose to restore the old value:
Index: grids.pas
===================================================================
--- grids.pas (revision 51675)
+++ grids.pas (working copy)
@@ -9613,6 +9613,7 @@
     VK_ESCAPE:
       begin
         doGridKeyDown;
+ SetEditText(FGrid.FEditorOldValue);
         FGrid.EditorHide;
       end;
     else

or add validation new value (ResetEditor proсeed validation):
Index: grids.pas
===================================================================
--- grids.pas (revision 51675)
+++ grids.pas (working copy)
@@ -9613,7 +9613,7 @@
     VK_ESCAPE:
       begin
         doGridKeyDown;
- FGrid.EditorHide;
+ FGrid.ResetEditor;
       end;
     else
       doEditorKeyDown;
TagsNo tags attached.
Fixed in Revision52707, 52749
LazTarget1.8
WidgetsetWin32/Win64
Attached Files
  • MyfavoriteGrid.zip (2,478 bytes)
  • dbgrids.pas.patch (2,279 bytes)
    Index: dbgrids.pas
    ===================================================================
    --- dbgrids.pas	(revision 43398)
    +++ dbgrids.pas	(working copy)
    @@ -617,7 +617,6 @@
     function CalcColumnFieldWidth(Canvas: TCanvas; hasTitle: boolean;
       aTitle: String; aTitleFont: TFont; Field: TField): Integer;
     var
    -  aCharWidth: Integer;
       aFont: TFont;
       UseTitleFont: boolean;
     begin
    @@ -625,12 +624,6 @@
         Result := DEFCOLWIDTH
       else begin
     
    -    aCharWidth := CalcCanvasCharWidth(Canvas);
    -    if Field.DisplayWidth>UTF8Length(aTitle) then
    -      result := aCharWidth * Field.DisplayWidth
    -    else
    -      result := aCharWidth * UTF8Length(aTitle);
    -
         if HasTitle then begin
           UseTitleFont :=
             (Canvas.Font.Size<>aTitleFont.Size) or
    @@ -643,15 +636,24 @@
             Canvas.Font := aTitleFont;
           end;
           try
    -        aCharWidth := Canvas.TextWidth(ATitle)+6;
    -        if aCharWidth>Result then
    -          Result := aCharWidth;
    +        result := Max(
    +          CalcCanvasCharWidth(Canvas) * Field.DisplayWidth,
    +          Canvas.TextWidth(aTitle) + 6
    +        );
           finally
             if UseTitleFont then begin
               Canvas.Font := aFont;
               aFont.Free;
             end;
           end;
    +
    +    end else begin
    +
    +      result := Max(
    +        CalcCanvasCharWidth(Canvas) * Field.DisplayWidth,
    +        Canvas.TextWidth(ATitle) + 6
    +      );
    +
         end; // if HasTitle ...
     
       end; // if (Field=nil) or (Field.DisplayWidth=0) ...
    @@ -1688,12 +1690,20 @@
     
           if (C<>nil) and (C.Title<>nil) then begin
             tmpCanvas.Font := C.Title.Font;
    -        ColWidth := tmpCanvas.TextWidth(trim(C.Title.Caption));
    +        ColWidth := tmpCanvas.TextWidth(C.Title.Caption);
    +        if Field<>nil then
    +          ColWidth := Max(
    +            CalcCanvasCharWidth(tmpCanvas) * Field.DisplayWidth,
    +            ColWidth
    +          );
             tmpCanvas.Font := C.Font;
           end else begin
             if (Field<>nil) then begin
               tmpCanvas.Font := TitleFont;
    -          ColWidth := tmpCanvas.TextWidth(Field.FieldName);
    +          ColWidth := Max(
    +            CalcCanvasCharWidth(tmpCanvas) * Field.DisplayWidth,
    +            tmpCanvas.TextWidth(Field.DisplayLabel)
    +          );
             end
             else
               ColWidth := 0;
    
    dbgrids.pas.patch (2,279 bytes)
  • grids.pas.patch (560 bytes)
    Index: lcl/grids.pas
    ===================================================================
    --- lcl/grids.pas	(revision 52739)
    +++ lcl/grids.pas	(working copy)
    @@ -7052,6 +7052,8 @@
               Key := 0;
             end;
           end;
    +    VK_ESCAPE:
    +      SetEditText(FCol, FRow, FEditorOldValue);
       end;
       if FEditorKey and (not PreserveRowAutoInserted) then
         FRowAutoInserted:=False;
    @@ -9689,7 +9691,6 @@
         VK_ESCAPE:
           begin
             doGridKeyDown;
    -        SetEditText(FGrid.FEditorOldValue);
             FGrid.EditorHide;
           end;
         else
    
    grids.pas.patch (560 bytes)

Activities

Jesus Reyes

2016-07-18 00:15

developer   ~0093747

Applied the version that restore the old value. Thank You.

malcome

2016-07-21 14:57

reporter   ~0093792

Last edited: 2016-07-22 01:57

View 2 revisions

Please give us freedom. New code is difficult to the same behavior as before. I want the Type-2).

Please see attached project. I usually create the Type-2 for myself.

malcome

2016-07-22 01:53

reporter  

MyfavoriteGrid.zip (2,478 bytes)

Jesus Reyes

2016-07-23 09:48

developer   ~0093799

Last edited: 2016-07-24 10:02

View 2 revisions

@malcome: When the validation succeed and you press ESCAPE obviously with the new code the old content is restored, with the old code the editor content is preserved in the cell, but this is precisely the expected behaviour after the change. When the validation does not succeed, I fail to notice any difference when pressing the ESCAPE key between the old grids code and the new one. However your comment in the VK_ESCAPE handler seems to suggest there is something is not possible anymore. Please clarify, what is wrong. If possible make a list of actions I should do to reproduce in order to reproduce the problem (select this, type this, click this, should do this but instead it does this, etc.)

malcome

2016-07-24 01:41

reporter  

dbgrids.pas.patch (2,279 bytes)
Index: dbgrids.pas
===================================================================
--- dbgrids.pas	(revision 43398)
+++ dbgrids.pas	(working copy)
@@ -617,7 +617,6 @@
 function CalcColumnFieldWidth(Canvas: TCanvas; hasTitle: boolean;
   aTitle: String; aTitleFont: TFont; Field: TField): Integer;
 var
-  aCharWidth: Integer;
   aFont: TFont;
   UseTitleFont: boolean;
 begin
@@ -625,12 +624,6 @@
     Result := DEFCOLWIDTH
   else begin
 
-    aCharWidth := CalcCanvasCharWidth(Canvas);
-    if Field.DisplayWidth>UTF8Length(aTitle) then
-      result := aCharWidth * Field.DisplayWidth
-    else
-      result := aCharWidth * UTF8Length(aTitle);
-
     if HasTitle then begin
       UseTitleFont :=
         (Canvas.Font.Size<>aTitleFont.Size) or
@@ -643,15 +636,24 @@
         Canvas.Font := aTitleFont;
       end;
       try
-        aCharWidth := Canvas.TextWidth(ATitle)+6;
-        if aCharWidth>Result then
-          Result := aCharWidth;
+        result := Max(
+          CalcCanvasCharWidth(Canvas) * Field.DisplayWidth,
+          Canvas.TextWidth(aTitle) + 6
+        );
       finally
         if UseTitleFont then begin
           Canvas.Font := aFont;
           aFont.Free;
         end;
       end;
+
+    end else begin
+
+      result := Max(
+        CalcCanvasCharWidth(Canvas) * Field.DisplayWidth,
+        Canvas.TextWidth(ATitle) + 6
+      );
+
     end; // if HasTitle ...
 
   end; // if (Field=nil) or (Field.DisplayWidth=0) ...
@@ -1688,12 +1690,20 @@
 
       if (C<>nil) and (C.Title<>nil) then begin
         tmpCanvas.Font := C.Title.Font;
-        ColWidth := tmpCanvas.TextWidth(trim(C.Title.Caption));
+        ColWidth := tmpCanvas.TextWidth(C.Title.Caption);
+        if Field<>nil then
+          ColWidth := Max(
+            CalcCanvasCharWidth(tmpCanvas) * Field.DisplayWidth,
+            ColWidth
+          );
         tmpCanvas.Font := C.Font;
       end else begin
         if (Field<>nil) then begin
           tmpCanvas.Font := TitleFont;
-          ColWidth := tmpCanvas.TextWidth(Field.FieldName);
+          ColWidth := Max(
+            CalcCanvasCharWidth(tmpCanvas) * Field.DisplayWidth,
+            tmpCanvas.TextWidth(Field.DisplayLabel)
+          );
         end
         else
           ColWidth := 0;
dbgrids.pas.patch (2,279 bytes)

malcome

2016-07-24 01:43

reporter   ~0093804

I propose a different patch.
IMHO your new code destroyed the flexibility and the grid component is basic component so I think you have to care the backward compatibility.

malcome

2016-07-24 01:44

reporter  

grids.pas.patch (560 bytes)
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 52739)
+++ lcl/grids.pas	(working copy)
@@ -7052,6 +7052,8 @@
           Key := 0;
         end;
       end;
+    VK_ESCAPE:
+      SetEditText(FCol, FRow, FEditorOldValue);
   end;
   if FEditorKey and (not PreserveRowAutoInserted) then
     FRowAutoInserted:=False;
@@ -9689,7 +9691,6 @@
     VK_ESCAPE:
       begin
         doGridKeyDown;
-        SetEditText(FGrid.FEditorOldValue);
         FGrid.EditorHide;
       end;
     else
grids.pas.patch (560 bytes)

malcome

2016-07-24 01:47

reporter   ~0093805

Sorry, "dbgrids.pas.patch" is another thing. I dont know how to delete it.

Jesus Reyes

2016-07-24 10:00

developer   ~0093810

It seems to me that

VK_ESCAPE:
  begin
    doGridKeyDown;
    if key<>0 then begin
      SetEditText(FGrid.FEditorOldValue);
      FGrid.EditorHide;
    end;
  end;

Should also do it. Yet, the previous code (before r52707), the "broken" code (r52707) and the proposed code (either your proposal or mine) needs to be tested. And with that in mind, I still require what I asked in my previous note, There is no need for new project, in your own project please supply the steps needed that support your "it's broken" claim.

malcome

2016-07-25 01:37

reporter   ~0093825

My "it's broken" claim?
I cannot understand it enough, do you mean that above MyfavoriteGrid project is no problem on the after r52707?
I just want to use the type-2 on the after r52707 same way as the before r52707.
If you say "Override your own InplaceEditor on the after r52707!", I will change all my projects codes.

Jesus Reyes

2016-07-25 20:50

developer   ~0093830

Yep, as I said in the note 0093799 I think you have a comment in your code about it.

I was simply trying to understand what do you mean by your comment but, as you don't want to provide the said steps to reproduce (or not) or explain the said problem, and you don't have any comment on my suggested patch versus yours, I will apply the mine. Please adjust your code as you like it, if modifying your code cannot be made because of my change, please open a new bug report about it.

I don't ask you to close this bug report because you are not the reporter :), Andrey Korol please close this report if there is nothing left in it.

Issue History

Date Modified Username Field Change
2016-04-22 10:46 Andrey Korol New Issue
2016-04-22 22:18 Bart Broersma Project Lazarus CCR => Lazarus
2016-04-23 07:23 Jesus Reyes Assigned To => Jesus Reyes
2016-04-23 07:23 Jesus Reyes Status new => assigned
2016-07-18 00:15 Jesus Reyes Fixed in Revision => 52707
2016-07-18 00:15 Jesus Reyes LazTarget => 1.8
2016-07-18 00:15 Jesus Reyes Note Added: 0093747
2016-07-18 00:15 Jesus Reyes Status assigned => resolved
2016-07-18 00:15 Jesus Reyes Fixed in Version => 1.7 (SVN)
2016-07-18 00:15 Jesus Reyes Resolution open => fixed
2016-07-18 00:15 Jesus Reyes Target Version => 1.8
2016-07-21 14:57 malcome Note Added: 0093792
2016-07-22 01:53 malcome File Added: MyfavoriteGrid.zip
2016-07-22 01:57 malcome Note Edited: 0093792 View Revisions
2016-07-23 09:48 Jesus Reyes Note Added: 0093799
2016-07-24 01:41 malcome File Added: dbgrids.pas.patch
2016-07-24 01:43 malcome Note Added: 0093804
2016-07-24 01:44 malcome File Added: grids.pas.patch
2016-07-24 01:47 malcome Note Added: 0093805
2016-07-24 10:00 Jesus Reyes Note Added: 0093810
2016-07-24 10:02 Jesus Reyes Note Edited: 0093799 View Revisions
2016-07-25 01:37 malcome Note Added: 0093825
2016-07-25 20:50 Jesus Reyes Note Added: 0093830
2016-07-25 20:51 Jesus Reyes Fixed in Revision 52707 => 52707, 52749
2016-07-25 22:38 Andrey Korol Status resolved => closed