View Issue Details

IDProjectCategoryView StatusLast Update
0026033PatchesLCLpublic2018-06-06 00:40
Reportererrno Assigned ToZeljan Rikalo  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformallOSall 
Product Version1.2.0 
Summary0026033: TCustomListView bug + patch
DescriptionTCustomListView.GetNextItem is buggy and return wrong result .
The states are the state flags we want .
I have made some changes in TCustomListView.GetNextItem in file customlistview.inc to fix the bug.
see attached file customlistview.inc .
Steps To Reproduceuse a tlistview with tlistview.GetNextItem
TagsNo tags attached.
Fixed in Revision44997
LazTarget-
Widgetset
Attached Files

Activities

errno

2014-04-16 17:23

reporter  

customlistview.inc (51,681 bytes)

Zeljan Rikalo

2014-04-16 19:04

developer   ~0074429

Please, learn how to create patch and then attach it.
http://wiki.lazarus.freepascal.org/Creating_A_Patch
http://wiki.lazarus.freepascal.org/How_To_Help_Developing_Lazarus

errno

2014-04-17 16:06

reporter  

customlistview.inc.patch (3,875 bytes)   
Index: lcl/include/customlistview.inc
===================================================================
--- lcl/include/customlistview.inc	(revision 44749)
+++ lcl/include/customlistview.inc	(working copy)
@@ -1204,8 +1204,7 @@
   end;
 end;
 
-function TCustomListView.GetNextItem(StartItem: TListItem;
-  Direction: TSearchDirection; States: TListItemStates): TListItem;
+function TCustomListView.GetNextItem(StartItem: TListItem;Direction: TSearchDirection; States: TListItemStates): TListItem;
 var
   ACount: Integer;
   AIndex: Integer;
@@ -1214,50 +1213,49 @@
   function GetItemStatesInternal(AItem: TListItem): TListItemStates;
   begin
     Result := [];
-    if AItem.GetState(Ord(lisCut)) then
-      ;
-    if AItem.GetState(Ord(lisDropTarget)) then
-      ;
-    if AItem.GetState(Ord(lisSelected)) then
-      ;
-    if AItem.GetState(Ord(lisFocused)) then
-      ;
+    if AItem.GetState(Ord(lisCut)) then ;
+    if AItem.GetState(Ord(lisDropTarget)) then ;
+    if AItem.GetState(Ord(lisSelected)) then ;
+    if AItem.GetState(Ord(lisFocused)) then ;
     Result := AItem.FStates;
   end;
 
 begin
-  Result := nil;
-  if Assigned(StartItem) then
-  begin
-    AIndex := StartItem.Index;
-    ACount := Items.Count;
-    case Direction of
-      sdAbove: if (AIndex -1) >= 0 then Result := Items[AIndex - 1];
-      sdBelow: if (Aindex + 1) < ACount then Result := Items[AIndex + 1];
-      sdAll:
-        while True do
-        begin
-          inc(AIndex);
-          if AIndex = StartItem.Index then
-          begin
-            Result := nil;
-            Exit;
-          end;
-          if AIndex >= ACount then
-            AIndex := -1;
-          if (AIndex >= 0) and (AIndex < ACount) then
-          begin
-            Result := Items[AIndex];
-            if GetItemStatesInternal(Result) - States = [] then
-              Exit;
-          end;
-        end;
-    end;
-    if Result = nil then
-      exit;
-    if (GetItemStatesInternal(Result) * States = []) then
-      Result := nil;
-  end
+Result:=nil;
+if Assigned(StartItem) then
+ begin
+ AIndex := StartItem.Index;
+ ACount := Items.Count;
+  case Direction of
+    sdAbove:while AIndex>0 do begin
+                              dec(AIndex);
+                              if states<=GetItemStatesInternal(Items[AIndex]) then begin
+                                                                                   Result:=Items[AIndex];
+                                                                                   exit;
+                                                                                   end;
+                              end;
+    sdBelow:while AIndex<ACount-1 do begin
+                                     inc(AIndex);
+                                     if states<=GetItemStatesInternal(Items[AIndex]) then begin
+                                                                                          Result:=Items[AIndex];
+                                                                                          exit;
+                                                                                          end;
+                                     end;
+    sdAll:while True do
+           begin
+           inc(AIndex);
+           if AIndex=StartItem.Index then Exit;
+           if AIndex>ACount-1 then begin
+                                   AIndex:=-1;
+                                   continue;
+                                   end;
+           if states<=GetItemStatesInternal(Items[AIndex]) then begin;
+                                                                result:=Items[AIndex];
+                                                                exit;
+                                                                end;
+           end;
+  end;
+ end;
 end;
 
 procedure TCustomListView.ClearSelection;
customlistview.inc.patch (3,875 bytes)   

errno

2014-04-17 16:07

reporter   ~0074443

Last edited: 2014-04-17 16:52

View 2 revisions

here is a patch made with tortoiseSVN.
Bug exists also in SVN version .

Zeljan Rikalo

2014-04-17 17:31

developer   ~0074444

Please attach example project where bug is visible (sorry I forgot to mention that in my last comment), also code in your patch isn't formatted well but I can do that for this time.

errno

2014-04-17 20:48

reporter  

listviewSample.zip (129,986 bytes)

errno

2014-04-17 20:50

reporter   ~0074446

i have attached an example

errno

2014-04-22 17:24

reporter  

listviewSample2.zip (66,792 bytes)

errno

2014-04-22 17:26

reporter   ~0074522

added listviewSample2.zip
just fix minor bug in sample and little changes

Zeljan Rikalo

2014-05-10 21:37

developer   ~0074889

I've formatted your patch according to our rules.
Please test and close if ok, and thanks for the patch.

Zeljan Rikalo

2014-05-10 21:40

developer   ~0074890

I need your name to add you to the contributors list if you aren't already there.

Issue History

Date Modified Username Field Change
2014-04-16 17:23 errno New Issue
2014-04-16 17:23 errno File Added: customlistview.inc
2014-04-16 19:04 Zeljan Rikalo LazTarget => -
2014-04-16 19:04 Zeljan Rikalo Note Added: 0074429
2014-04-16 19:04 Zeljan Rikalo Assigned To => Zeljan Rikalo
2014-04-16 19:04 Zeljan Rikalo Status new => feedback
2014-04-17 16:06 errno File Added: customlistview.inc.patch
2014-04-17 16:07 errno Note Added: 0074443
2014-04-17 16:07 errno Status feedback => assigned
2014-04-17 16:52 errno Note Edited: 0074443 View Revisions
2014-04-17 17:31 Zeljan Rikalo Note Added: 0074444
2014-04-17 17:31 Zeljan Rikalo Status assigned => feedback
2014-04-17 20:48 errno File Added: listviewSample.zip
2014-04-17 20:50 errno Note Added: 0074446
2014-04-17 20:50 errno Status feedback => assigned
2014-04-22 17:24 errno File Added: listviewSample2.zip
2014-04-22 17:26 errno Note Added: 0074522
2014-05-10 21:37 Zeljan Rikalo Fixed in Revision => 44997
2014-05-10 21:37 Zeljan Rikalo Note Added: 0074889
2014-05-10 21:37 Zeljan Rikalo Status assigned => resolved
2014-05-10 21:37 Zeljan Rikalo Resolution open => fixed
2014-05-10 21:40 Zeljan Rikalo Note Added: 0074890
2018-06-06 00:40 errno Status resolved => closed