View Issue Details

IDProjectCategoryView StatusLast Update
0014371LazarusLCLpublic2011-12-01 11:23
ReporterEddyAssigned ToPaul Ishenin 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.27 (SVN)Product Build 
Target Version1.0.0Fixed in Version0.9.29 (SVN) 
Summary0014371: TListView does not give the correct column widths when in FormDestroy
DescriptionWhen in a FormDestroy event and accessing the column widhts of a TListView (report style), the column widths are wrong. Not the actual column widths are given, but the column widths at the time of program start (design time widths).
Tested with: Lazarus-0.9.27-21258-fpc-2.2.5-20090817-win32.
(The problem occurred in a June-2009 version, but still exists in the latest version.)
Additional InformationThe attached example shows the problem: change the width of any column and move the mouse cursor over the listview: this updates the form caption so the correct widths are shown. Then close the application. A file is written that shows the incorrect column widths.
TagsNo tags attached.
Fixed in Revision25124
LazTarget1.0
WidgetsetWin32/Win64
Attached Files
  • columnwidths.zip (159,081 bytes)
  • wsreadallowed_listcolum_getwidth.patch (1,257 bytes)
    Index: comctrls.pp
    ===================================================================
    --- comctrls.pp	(revision 21261)
    +++ comctrls.pp	(working copy)
    @@ -792,6 +792,7 @@
         procedure WSCreateColumn;
         procedure WSDestroyColumn;
         function  WSUpdateAllowed: Boolean;
    +    function  WSReadAllowed: Boolean;
         procedure SetVisible(const AValue: Boolean);
         procedure SetAutoSize(const AValue: Boolean);
         procedure SetMinWidth(const AValue: TWidth);
    Index: include/listcolumn.inc
    ===================================================================
    --- include/listcolumn.inc	(revision 21261)
    +++ include/listcolumn.inc	(working copy)
    @@ -116,12 +116,19 @@
         and not (csDestroying in TListColumns(Collection).FOwner.ComponentState);
     end;
     
    +function TListColumn.WSReadAllowed: Boolean;
    +begin
    +  Result := (Collection <> nil)
    +    and (TListColumns(Collection).FOwner <> nil)
    +    and TListColumns(Collection).FOwner.HandleAllocated
    +end;
    +
     function TListColumn.GetWidth: TWidth;
     var
       LV: TCustomListView;
       WSWidth: integer;
     begin
    -  if WSUpdateAllowed
    +  if WSReadAllowed
       then begin
         LV := TListColumns(Collection).FOwner;
         WSWidth := TWSCustomListViewClass(LV.WidgetSetClass).ColumnGetWidth(LV, Index, Self);
    

Activities

2009-08-17 17:45

 

columnwidths.zip (159,081 bytes)

José Mejuto

2009-08-18 00:44

reporter   ~0029944

The bug or Delphi non compatible behavior is related to the fact that at FormDestroy the TListView is at componentstate csDestroying which prevent (via WSUpdateAllowed function) the right Width to be read from the underlaying object. As .Get is a read operation it should success when the handle is allowcated independently that if it is at csDestroying or not. I had added a new WSReadAllowed function that is being checked instead WSUpdateAllowed without the componentstate check as the worst thing could be wrong values at reading stage.
I think similar function could be added to .Get functions.
I'll attach a proposed patch.

2009-08-18 00:45

 

wsreadallowed_listcolum_getwidth.patch (1,257 bytes)
Index: comctrls.pp
===================================================================
--- comctrls.pp	(revision 21261)
+++ comctrls.pp	(working copy)
@@ -792,6 +792,7 @@
     procedure WSCreateColumn;
     procedure WSDestroyColumn;
     function  WSUpdateAllowed: Boolean;
+    function  WSReadAllowed: Boolean;
     procedure SetVisible(const AValue: Boolean);
     procedure SetAutoSize(const AValue: Boolean);
     procedure SetMinWidth(const AValue: TWidth);
Index: include/listcolumn.inc
===================================================================
--- include/listcolumn.inc	(revision 21261)
+++ include/listcolumn.inc	(working copy)
@@ -116,12 +116,19 @@
     and not (csDestroying in TListColumns(Collection).FOwner.ComponentState);
 end;
 
+function TListColumn.WSReadAllowed: Boolean;
+begin
+  Result := (Collection <> nil)
+    and (TListColumns(Collection).FOwner <> nil)
+    and TListColumns(Collection).FOwner.HandleAllocated
+end;
+
 function TListColumn.GetWidth: TWidth;
 var
   LV: TCustomListView;
   WSWidth: integer;
 begin
-  if WSUpdateAllowed
+  if WSReadAllowed
   then begin
     LV := TListColumns(Collection).FOwner;
     WSWidth := TWSCustomListViewClass(LV.WidgetSetClass).ColumnGetWidth(LV, Index, Self);

Paul Ishenin

2010-05-02 08:45

manager   ~0037155

Please test and close if ok.

Issue History

Date Modified Username Field Change
2009-08-17 17:45 Eddy New Issue
2009-08-17 17:45 Eddy File Added: columnwidths.zip
2009-08-17 17:45 Eddy Widgetset => Win32/Win64
2009-08-17 21:28 Vincent Snijders LazTarget => 1.0
2009-08-17 21:28 Vincent Snijders Status new => acknowledged
2009-08-17 21:28 Vincent Snijders Target Version => 1.0.0
2009-08-18 00:44 José Mejuto Note Added: 0029944
2009-08-18 00:45 José Mejuto File Added: wsreadallowed_listcolum_getwidth.patch
2010-05-02 08:45 Paul Ishenin Fixed in Revision => 25124
2010-05-02 08:45 Paul Ishenin Status acknowledged => resolved
2010-05-02 08:45 Paul Ishenin Fixed in Version => 0.9.29 (SVN)
2010-05-02 08:45 Paul Ishenin Resolution open => fixed
2010-05-02 08:45 Paul Ishenin Assigned To => Paul Ishenin
2010-05-02 08:45 Paul Ishenin Note Added: 0037155
2011-12-01 11:23 Marc Weustink Status resolved => closed