mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 18:19:34 +02:00
LCL, TreeView: fix the logic for allocating an array for visible nodes
git-svn-id: trunk@34663 -
This commit is contained in:
parent
da787feb8d
commit
6066424d39
@ -78,18 +78,20 @@ function IndexOfNodeAtTop(NodeArray: TTreeNodeArray; Count, y: integer): integer
|
|||||||
// returns index of Node with Node.Top <= y < Node[+1].Top
|
// returns index of Node with Node.Top <= y < Node[+1].Top
|
||||||
var
|
var
|
||||||
l, m, r, VisibleCount: integer;
|
l, m, r, VisibleCount: integer;
|
||||||
|
VisibleNodesAlloc: Boolean;
|
||||||
VisibleNodes: TTreeNodeArray;
|
VisibleNodes: TTreeNodeArray;
|
||||||
begin
|
begin
|
||||||
if (Count = 0) or (NodeArray = nil) then
|
if (Count = 0) or (NodeArray = nil) then
|
||||||
Exit(-1);
|
Exit(-1);
|
||||||
// Count the visible nodes
|
// Count the visible nodes
|
||||||
VisibleCount := 0;
|
VisibleCount := 0;
|
||||||
|
VisibleNodesAlloc := False;
|
||||||
for l := 0 to Count-1 do
|
for l := 0 to Count-1 do
|
||||||
if NodeArray[l].Visible then
|
if NodeArray[l].Visible then
|
||||||
Inc(VisibleCount);
|
Inc(VisibleCount);
|
||||||
try
|
try
|
||||||
// Make a temporary array of visible nodes
|
// Make a temporary array of visible nodes if there are hidden nodes
|
||||||
if VisibleCount > 0 then begin
|
if VisibleCount < Count then begin
|
||||||
GetMem(VisibleNodes,SizeOf(Pointer)*VisibleCount);
|
GetMem(VisibleNodes,SizeOf(Pointer)*VisibleCount);
|
||||||
m := 0;
|
m := 0;
|
||||||
for l := 0 to Count-1 do
|
for l := 0 to Count-1 do
|
||||||
@ -98,6 +100,7 @@ begin
|
|||||||
Inc(m);
|
Inc(m);
|
||||||
end;
|
end;
|
||||||
Count := VisibleCount;
|
Count := VisibleCount;
|
||||||
|
VisibleNodesAlloc := True;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
VisibleNodes := NodeArray;
|
VisibleNodes := NodeArray;
|
||||||
@ -117,7 +120,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
Result := -1;
|
Result := -1;
|
||||||
finally
|
finally
|
||||||
if VisibleCount > 0 then
|
if VisibleNodesAlloc then
|
||||||
Freemem(VisibleNodes);
|
Freemem(VisibleNodes);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user