Deleting item in Firemonkey TListView causes out of range exception

  

I have a TListView with several items where each item has a corresponding “Remove” button. The TListView has the following on button click event handler:

void __fastcall TSettingsCopyWizard_Fac::CopyToListViewButtonClick(TObject * const Sender,
TListViewItem * const AItem, TListItemSimpleControl * const AObject)

{
CopyToListView->BeginUpdate();
CopyToListView->Items->Delete(AItem->Index);
CopyToListView->EndUpdate();
}

When I try to delete an item, an “Arguments out of range” exception is thrown. However, it is not on the Delete call, rather in System.Generics.Collections here:

procedure TListHelper.CheckItemRange(AIndex: Integer);
begin
CheckItemRangeInline(AIndex); //this is the line that throws the exception
end;

Am I improperly deleting an item from my list view? Or is there something else causing this issue?

Comments are closed.