Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 28 Mar 2024, 16:31

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: 09 Aug 2018, 09:17 
Offline

Joined: 08 Sep 2017, 10:37
Posts: 8
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 59 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group