View Issue Details

IDProjectCategoryView StatusLast Update
0028959LazarusPatchpublic2016-03-09 16:16
ReporterGabor BorosAssigned ToOndrej Pokorny 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product VersionProduct Build 
Target VersionFixed in Version1.6 
Summary0028959: Access to the real size of the columns of the grids
DescriptionI want to save/load size of grid columns. But With property returns 0 value for non visible columns. Attached patch(es) contains a new property which returns column size independently from value of Visible property.
TagsNo tags attached.
Fixed in Revision50262, 50267, 50371
LazTarget-
Widgetset
Attached Files
  • grids.pas_fixes_1_4_50205.patch (1,065 bytes)
    Index: lcl/grids.pas
    ===================================================================
    --- lcl/grids.pas	(revision 50217)
    +++ lcl/grids.pas	(working copy)
    @@ -488,6 +488,7 @@
         function GetReadOnly: Boolean;
         function GetVisible: Boolean;
         function GetWidth: Integer;
    +    function GetRealWidth: Integer;
         function IsAlignmentStored: boolean;
         function IsColorStored: boolean;
         function IsFontStored: boolean;
    @@ -546,6 +547,7 @@
         function  IsDefault: boolean; virtual;
         property Grid: TCustomGrid read GetGrid;
         property WidthChanged: boolean read FWidthChanged;
    +    property RealWidth: Integer read GetRealWidth;
     
       published
         property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
    @@ -11314,6 +11316,14 @@
         result := FWidth^;
     end;
     
    +function TGridColumn.GetRealWidth: Integer;
    +begin
    +  if FWidth=nil then
    +    result := GetDefaultWidth
    +  else
    +    result := FWidth^;
    +end;
    +
     function TGridColumn.IsAlignmentStored: boolean;
     begin
       result := FAlignment <> nil;
    
  • grids.pas_trunk_50217.patch (1,065 bytes)
    Index: lcl/grids.pas
    ===================================================================
    --- lcl/grids.pas	(revision 50217)
    +++ lcl/grids.pas	(working copy)
    @@ -501,6 +501,7 @@
         function GetReadOnly: Boolean;
         function GetVisible: Boolean;
         function GetWidth: Integer;
    +    function GetRealWidth: Integer;
         function IsAlignmentStored: boolean;
         function IsColorStored: boolean;
         function IsFontStored: boolean;
    @@ -559,6 +560,7 @@
         function  IsDefault: boolean; virtual;
         property Grid: TCustomGrid read GetGrid;
         property WidthChanged: boolean read FWidthChanged;
    +    property RealWidth: Integer read GetRealWidth;
     
       published
         property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
    @@ -11432,6 +11434,14 @@
         result := FWidth^;
     end;
     
    +function TGridColumn.GetRealWidth: Integer;
    +begin
    +  if FWidth=nil then
    +    result := GetDefaultWidth
    +  else
    +    result := FWidth^;
    +end;
    +
     function TGridColumn.IsAlignmentStored: boolean;
     begin
       result := FAlignment <> nil;
    
  • bug28959.tar.gz (1,563 bytes)

Activities

Gabor Boros

2015-11-04 10:52

reporter  

grids.pas_fixes_1_4_50205.patch (1,065 bytes)
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 50217)
+++ lcl/grids.pas	(working copy)
@@ -488,6 +488,7 @@
     function GetReadOnly: Boolean;
     function GetVisible: Boolean;
     function GetWidth: Integer;
+    function GetRealWidth: Integer;
     function IsAlignmentStored: boolean;
     function IsColorStored: boolean;
     function IsFontStored: boolean;
@@ -546,6 +547,7 @@
     function  IsDefault: boolean; virtual;
     property Grid: TCustomGrid read GetGrid;
     property WidthChanged: boolean read FWidthChanged;
+    property RealWidth: Integer read GetRealWidth;
 
   published
     property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
@@ -11314,6 +11316,14 @@
     result := FWidth^;
 end;
 
+function TGridColumn.GetRealWidth: Integer;
+begin
+  if FWidth=nil then
+    result := GetDefaultWidth
+  else
+    result := FWidth^;
+end;
+
 function TGridColumn.IsAlignmentStored: boolean;
 begin
   result := FAlignment <> nil;

Gabor Boros

2015-11-04 10:52

reporter  

grids.pas_trunk_50217.patch (1,065 bytes)
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 50217)
+++ lcl/grids.pas	(working copy)
@@ -501,6 +501,7 @@
     function GetReadOnly: Boolean;
     function GetVisible: Boolean;
     function GetWidth: Integer;
+    function GetRealWidth: Integer;
     function IsAlignmentStored: boolean;
     function IsColorStored: boolean;
     function IsFontStored: boolean;
@@ -559,6 +560,7 @@
     function  IsDefault: boolean; virtual;
     property Grid: TCustomGrid read GetGrid;
     property WidthChanged: boolean read FWidthChanged;
+    property RealWidth: Integer read GetRealWidth;
 
   published
     property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
@@ -11432,6 +11434,14 @@
     result := FWidth^;
 end;
 
+function TGridColumn.GetRealWidth: Integer;
+begin
+  if FWidth=nil then
+    result := GetDefaultWidth
+  else
+    result := FWidth^;
+end;
+
 function TGridColumn.IsAlignmentStored: boolean;
 begin
   result := FAlignment <> nil;

Ondrej Pokorny

2015-11-04 13:14

reporter   ~0087115

Last edited: 2015-11-04 13:14

View 2 revisions

The patch looks good to me. I don't like the property name. Any other suggestions? (Juha?)

Maybe "StoredWidth"?

+ What about Rows and Height?

Gabor Boros

2015-11-04 13:46

reporter   ~0087116

Named after TGridColumns.RealIndex. Please rename if needed.

Ondrej Pokorny

2015-11-04 16:49

reporter   ~0087123

>> Named after TGridColumns.RealIndex.

This is a wrong choice indeed. RealIndex returns ({$ifndef NewCols}) the index *without* hidden columns.

Therefore "RealWidth" should return 0 for an invisible column and "Width" should return the stored width, IMO. - But as the Width property shouldn't be changed, we need a different name. RealWidth is not good.

+ What about Rows and Height? It's the same story (Height=0 for invisible rows)?

Gabor Boros

2015-11-04 19:26

reporter   ~0087125

Ok, Real is wrong choice.

Mixing two properties in one getter is very bad idea from my POV. With my logic the best solution is a Width property which return FWidth and a VisibleWidth property which return FWitdh for visible columns and 0 for non visible columns.
But this not an easy change with thousand of existing Lazarus users.

I use dbgrids only. But examined and TStringGrid.Rows is TStrings, TStringGrid.RowHeights return the stored values from a TList. Visible property not exists for rows.

Ondrej Pokorny

2015-11-09 11:00

reporter   ~0087205

I used StoredWidth. Note that it returns -1 if the column has default width.
You can use -1 to set Width of the column to default back.

Please test and close if OK.

Gabor Boros

2015-11-09 17:30

reporter   ~0087209

Tested and works. Thanks a lot!

Gabor Boros

2015-11-09 22:43

reporter   ~0087211

Said fixed too early. Sorry. Worked with a simple test case but not in real life. With the attached example StoredWidth return -1 always(with visible and not visible column too).

Gabor Boros

2015-11-09 22:44

reporter  

bug28959.tar.gz (1,563 bytes)

Ondrej Pokorny

2015-11-09 22:47

reporter   ~0087212

Yes, that's correct. -1 is returned regardless if the column is visible or not. AFAIK this is what you want: "Attached patch(es) contains a new property which returns column size independently from value of Visible property."

Gabor Boros

2015-11-09 23:46

reporter   ~0087213

Last edited: 2015-11-09 23:48

View 3 revisions

My patch is correct, the applied is not. With my patch(after modify the property name) the attached example in original state display 360 360 on the form caption with Windows for me. If remove the double slash from visible line, caption is 0 360. This is what I want. I know the width of a non visible column. With latest trunk the caption is 360 -1 if the column visible and 0 -1 if not. StoredWidth always return -1 which is wrong.

Ondrej Pokorny

2015-11-10 05:30

reporter   ~0087214

Last edited: 2015-11-10 05:47

View 3 revisions

>> StoredWidth always return -1 which is wrong.

This is correct. Did you read 0028959:0087205? -1 is returned because the column has not stored any width. The width of the column is default, thus StoredWidth returns -1. You can assign -1 to Width to set default width back.

If you don't like to see -1, use the DefaultWidth property (rev 50267) in case StoredWidth returns -1:
  if Columns[0].StoredWidth < 0 then
     Self.Caption:=IntToStr(Columns[0].Width)+' '+IntToStr(Columns[0].DefaultWidth)
  else
     Self.Caption:=IntToStr(Columns[0].Width)+' '+IntToStr(Columns[0].StoredWidth);

But you can normally save -1 to your settings and load -1 back - it will work like a charm, no need to use DefaultWidth.

Gabor Boros

2015-11-10 11:59

reporter   ~0087216

My fault. Sorry. Next time I try to understand -1 at morning and not at late night. The attached example not contains the column resize step and that is why I got -1 always. Now works like a charm. I'm really sorry to have wasted your time. Thank you very much for your work!

Gabor Boros

2015-11-16 19:19

reporter   ~0087327

I found a regression. If resize a column to zero (with mouse), width of column jump to default value.

Ondrej Pokorny

2015-11-17 18:56

reporter   ~0087364

Yes, wrong comparison operator. Thanks for finding this!

Issue History

Date Modified Username Field Change
2015-11-04 10:52 Gabor Boros New Issue
2015-11-04 10:52 Gabor Boros File Added: grids.pas_fixes_1_4_50205.patch
2015-11-04 10:52 Gabor Boros File Added: grids.pas_trunk_50217.patch
2015-11-04 13:14 Ondrej Pokorny Note Added: 0087115
2015-11-04 13:14 Ondrej Pokorny Note Edited: 0087115 View Revisions
2015-11-04 13:46 Gabor Boros Note Added: 0087116
2015-11-04 16:49 Ondrej Pokorny Note Added: 0087123
2015-11-04 19:26 Gabor Boros Note Added: 0087125
2015-11-04 22:16 Ondrej Pokorny Assigned To => Ondrej Pokorny
2015-11-04 22:16 Ondrej Pokorny Status new => assigned
2015-11-09 11:00 Ondrej Pokorny Fixed in Revision => 50262
2015-11-09 11:00 Ondrej Pokorny LazTarget => -
2015-11-09 11:00 Ondrej Pokorny Note Added: 0087205
2015-11-09 11:00 Ondrej Pokorny Status assigned => resolved
2015-11-09 11:00 Ondrej Pokorny Fixed in Version => 1.6
2015-11-09 11:00 Ondrej Pokorny Resolution open => fixed
2015-11-09 17:30 Gabor Boros Note Added: 0087209
2015-11-09 17:30 Gabor Boros Status resolved => closed
2015-11-09 22:43 Gabor Boros Note Added: 0087211
2015-11-09 22:43 Gabor Boros Status closed => assigned
2015-11-09 22:43 Gabor Boros Resolution fixed => reopened
2015-11-09 22:44 Gabor Boros File Added: bug28959.tar.gz
2015-11-09 22:47 Ondrej Pokorny Note Added: 0087212
2015-11-09 23:46 Gabor Boros Note Added: 0087213
2015-11-09 23:47 Gabor Boros Note Edited: 0087213 View Revisions
2015-11-09 23:48 Gabor Boros Note Edited: 0087213 View Revisions
2015-11-10 05:30 Ondrej Pokorny Note Added: 0087214
2015-11-10 05:31 Ondrej Pokorny Note Edited: 0087214 View Revisions
2015-11-10 05:33 Ondrej Pokorny Fixed in Revision 50262 => 50262, 50267
2015-11-10 05:33 Ondrej Pokorny Status assigned => resolved
2015-11-10 05:33 Ondrej Pokorny Resolution reopened => fixed
2015-11-10 05:47 Ondrej Pokorny Note Edited: 0087214 View Revisions
2015-11-10 11:59 Gabor Boros Note Added: 0087216
2015-11-16 19:19 Gabor Boros Note Added: 0087327
2015-11-16 19:19 Gabor Boros Status resolved => assigned
2015-11-16 19:19 Gabor Boros Resolution fixed => reopened
2015-11-17 18:56 Ondrej Pokorny Fixed in Revision 50262, 50267 => 50262, 50267, 50371
2015-11-17 18:56 Ondrej Pokorny Note Added: 0087364
2015-11-17 18:56 Ondrej Pokorny Status assigned => resolved
2015-11-17 18:56 Ondrej Pokorny Resolution reopened => fixed
2016-03-09 16:16 Gabor Boros Status resolved => closed