EhLib.Com https://forum.ehlib.com/en/ |
|
MemTableEh list index out of bound https://forum.ehlib.com/en/viewtopic.php?f=5&t=831 |
Page 1 of 1 |
Author: | Svetoslav [ 09 Aug 2018, 09:17 ] |
Post subject: | MemTableEh list index out of bound |
Hello, We have found that an "List index out of bound" exception is triggered in a specific situation when searching in a TMemTableEh in a TreeMode. I will try to explain below the issue: We are using a TMemTableEh in a tree view with FilterOnTyping Search Panel and after a DBGridEh.OnKeyPress event is triggered the control enters this function: Code: function TTreeListEh.GetNextVisibleSibling(Node: TBaseTreeNodeEh): TBaseTreeNodeEh; begin if Node.Parent.Count = Node.Parent.VisibleCount then Result := GetNextSibling(Node) else begin if (Node = nil) or (Node.Parent = nil) or (Node.VisibleIndex = Node.Parent.VisibleCount - 1) then begin Result := nil; Exit; end; Result := Node.Parent.VisibleItem[Node.VisibleIndex + 1]; end; end; Depending on the current data, Node.Parent.Count will not be = Node.Parent.VisibleCount and it will enter the else case. At the Code: Result := Node.Parent.VisibleItem[Node.VisibleIndex + 1]; the application will try to access the n-th index of Node.Parent.VisibleItem, entering the function:Code: function TBaseTreeNodeEh.GetVisibleItem(const Index: Integer): TBaseTreeNodeEh; begin if FVisibleItemsObsolete then InternalBuildVisibleItems; Result := TBaseTreeNodeEh(VisibleItems[Index]); end; And to get the VisibleItems list will enter the: Code: function TBaseTreeNodeEh.VisibleItems: TObjectList; begin if FVisibleItemsObsolete then InternalBuildVisibleItems; if Count = VisibleCount then Result := FItems else Result := FVisibleItems; end; Here is where the issue is. If Count <> VisibleCount, the function will return the FVisibleItems list. But the list may be empty (in out situation it is) and trying to access Index 3 for example will trigger the list index out of bounds exception. The problem can be reproduced with the TreeView demo, by adding SearchPanel and FilterOnTyping on the grid and at least one OnGetText event on the fields of the MemTableEh. We are using Delphi 10.2 and EhLib 9.2.025 Thank you, Best Regards. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |