如何使循环删除目录中的所选项目

时间:2017-09-14 11:45:51

标签: android delphi firemonkey delphi-10.2-tokyo

我想创建一个循环,以便从listview中删除所选项目。

procedure TFContact.BtnDeleteClick(Sender: TObject);
var
SecItem, BUFPath : string;
i : Integer;
begin
   if ListViewTab5.Selected <> nil then

    for i := 0 to ListViewTab5.Items.Count - 1 do
    begin
    SecItem:= TListViewItem(ListViewTab5.Selected).Text;
    BUFPath:= '/storage/emulated/0/Backup/'+SecItem;
    TFile.Delete(BUFPath);
    end
    else
    ShowMessage('File Deleted Succesfully');
end;

1 个答案:

答案 0 :(得分:1)

试试这个:

procedure TFContact.BtnDeleteClick(Sender: TObject);
const
  Path = '/storage/emulated/0/Backup/';
var
  Item: TListViewItem;
begin
  for Item in ListView.Items do
    if Item.Checked then
      TFile.Delete(TPath.Combine(Path, Item.Text));
end;