Попробуйте вот так (не самый идеальный вариант, но он работает и ошибок не выдает).
procedure TForm1.Button1Click(Sender: TObject);
begin
var selectedItems: TArray<TListBoxItem>; // Объявляем массив из объектов TListBoxItem
for var item: TFMXObject in ListBox1.Children.Items[1].Children do // Перебираем каждый дочерний компонент в ListBox, который является экземпляром класса TListBoxItem.
begin
if item is TListBoxItem then // Проверяем, является ли item экземпляром класса TListBoxItem
if TListBoxItem(item).IsChecked then // Проверяем, является ли элемент отмеченным галочкой
begin
System.SetLength(selectedItems, System.Length(selectedItems) + 1); // Увеличиваем длину массива
selectedItems[High(selectedItems)] := TListBoxItem(item); // Вставляем элемент в массив
end;
end;
DeleteAllCheckedFiles(selectedItems);
end;
procedure TForm1.DeleteAllCheckedFiles(items: TArray<TListBoxItem>);
begin
if System.Length(items) < 1 then Exit;
for var i: Integer := 0 to System.Length(items) - 1 do
begin
var item: TListBoxItem := items[i];
if Assigned(item) then
begin
// TFile.Delete(item.Text);
item.Free(); // Освобождаем память, тем самым объект уничтожится и больше не будет находиться в списке элементов TListBox
end;
end;
end;