procedure TCustomListView.UpdateItemLookups;
var
I, TotalHeight, PrevItemHeight, CurHeaderRef: Integer;
begin
if FHeightSumsNeedUpdate then
begin
TotalHeight := 0;
if (FSearchEdit <> nil) and FSearchEdit.Visible then
TotalHeight := TotalHeight + Ceil(FSearchEdit.Height);
FHeightSums.Clear;
FHeightSums.Add(TotalHeight);
CurHeaderRef := -1;
for I := 0 to Items.Count - 1 do
begin
if I > 0 then
begin
PrevItemHeight := GetItemHeight(I - 1);
Inc(TotalHeight, PrevItemHeight);
FHeightSums.Add(TotalHeight);
end;
if Items[I].Purpose = TListItemPurpose.Header then
begin
CurHeaderRef := I;
TOpenListBoxItem(Items[I]).FHeaderRef := I;
end;
if Items[I].Purpose = TListItemPurpose.None then
begin
if Items[I].Count > 0 then
TOpenListBoxItem(Items[I]).FHeaderRef := CurHeaderRef
else
CurHeaderRef := -1;
end;
end;
Inc(TotalHeight, GetItemHeight(Items.Count - 1));
if TotalHeight <> FMaxKnownHeight then
begin
FHeightSums.Add(TotalHeight); //S4:Fix added
FMaxKnownHeight := TotalHeight;
UpdateScrollingLimits;
end;
FHeightSumsNeedUpdate := False;
end;
end;
function TCustomListView.FindItemAbsoluteAt(ViewAt: Integer): Integer;
var
Left, Right, Pivot, Value: Integer;
iUp: Integer;
begin
UpdateItemLookups;
if Items.Count < 1 then
Exit(-1);
if ViewAt < 1 then
Exit(0);
if ViewAt >= FHeightSums[FHeightSums.Count - 1] then
Exit(-1); //S4:Fix: FHeightSums.Count - 1);
Left := 0;
Right := FHeightSums.Count - 1;
Pivot := 0;
while Left <= Right do
begin
Pivot := (Left + Right) div 2;
Value := FHeightSums[Pivot];
if Value = ViewAt then
Exit(Pivot);
if Value > ViewAt then
Right := Pivot - 1
else
Left := Pivot + 1;
end;
Result := Pivot;
if (Result > 0) and (Result < FHeightSums.Count) and (FHeightSums[Result] >= ViewAt) then
Dec(Result);
end;