I found this piece of code online somewhere, and wondering if this is a compiler error. Please note that the second parameter is named "ItemIndex". And also that within the with block below, the ListView has a ItemIndex property available to it. It seems as if the "ItemIndex" that is being referenced is the ListView one and not the parameter. Is the correct behavior? The workaround was easy, just change the parameter name.
Am I correct in my my question? The Editor's popups show it connected to the ListView. Anyway the execution has an exception.
procedure TForm1.ListViewSetTopItem(ListView: TListView; ItemIndex: Integer);
var
Difference, ItemHeight: Integer;
begin
if not (ListView.ViewStyle = vsReport) then
Exit;
if (ItemIndex < 0) or (ListView.Items.Count = 0) or
(ItemIndex > ListView.Items.Count - 1) then
raise EInvalidOperation.CreateFmt(SPropertyOutOfRange, ['TopItem']);
with ListView do
begin
Difference := TopItem.Index - Items.Item[ItemIndex].Index; // <-- THE ONE IN THIS LINE
with Items.Item[0].DisplayRect(drBounds) do
ItemHeight := Top - Bottom;
ScrollBy(0, Difference * ItemHeight);
end;
end;