LCL: Do not wrap around in TCustomListView.GetNextItem with search direction = sdAll. Issue #38565.

git-svn-id: trunk@64746 -
This commit is contained in:
juha 2021-03-05 09:52:34 +00:00
parent 8fde568fcc
commit 381d67724c

View File

@ -1347,7 +1347,7 @@ function TCustomListView.GetNextItem(StartItem: TListItem;
Direction: TSearchDirection; States: TListItemStates): TListItem; Direction: TSearchDirection; States: TListItemStates): TListItem;
var var
ACount: Integer; ACount: Integer;
AIndex: Integer; StartIndex, AIndex: Integer;
{TODO: create public property States which reads states of item} {TODO: create public property States which reads states of item}
function GetItemStatesInternal(AItem: TListItem): TListItemStates; function GetItemStatesInternal(AItem: TListItem): TListItemStates;
@ -1362,48 +1362,39 @@ var
begin begin
Result := nil; Result := nil;
if Assigned(StartItem) then if StartItem = nil then
begin Exit;
AIndex := StartItem.Index; StartIndex := StartItem.Index;
ACount := Items.Count; AIndex := StartIndex;
case Direction of ACount := Items.Count;
sdAbove: case Direction of
while AIndex>0 do sdAbove:
begin while AIndex>0 do
dec(AIndex); begin
if States <= GetItemStatesInternal(Items[AIndex]) then dec(AIndex);
begin if States <= GetItemStatesInternal(Items[AIndex]) then
Result := Items[AIndex]; Exit(Items[AIndex]);
exit; end;
end; sdBelow:
end; while AIndex < ACount-1 do
sdBelow: begin
while AIndex < ACount-1 do inc(AIndex);
begin if States <= GetItemStatesInternal(Items[AIndex]) then
inc(AIndex); Exit(Items[AIndex]);
if States <= GetItemStatesInternal(Items[AIndex]) then end;
begin sdAll:
Result := Items[AIndex]; while True do
exit; begin
end; inc(AIndex);
end; Assert(AIndex <> StartIndex, 'TCustomListView.GetNextItem: AIndex=StartIndex');
sdAll: if AIndex >= ACount then
while True do Exit;
begin { begin Do not wrap around. Will never return Nil. Issue #38565.
inc(AIndex); AIndex := -1; continue;
if AIndex = StartItem.Index then Exit; end; }
if AIndex > ACount-1 then if States <= GetItemStatesInternal(Items[AIndex]) then
begin Exit(Items[AIndex]);
AIndex := -1; end;
continue;
end;
if States <= GetItemStatesInternal(Items[AIndex]) then
begin
Result := Items[AIndex];
exit;
end;
end;
end;
end; end;
end; end;