procedure TForm1.miDelClick(Sender: TObject); var Node: PVirtualNode; item: TUpdataFile; index, ioffset: integer; begin ioffset := 0; Node := self.vstFiles.FocusedNode; if (not Assigned(Node)) then Exit; if (self.vstFiles.SelectedCount < 1) then Exit; try self.vstFiles.BeginUpdate; Node := vstFiles.GetFirstSelected(); // 特点从第一个选择开始删除的 while Assigned(Node) do begin item := self.fPack.List[Node.index - ioffset]; // 技巧 2017-1-19 11:27 self.fPack.DelFile(item); Node := vstFiles.GetNextSelected(Node); inc(ioffset); //每删除一个,就记录以及删除了多少个 end; finally self.vstFiles.RootNodeCount := self.fPack.List.Count; self.vstFiles.EndUpdate; self.vstFiles.Invalidate; end; end;
注:此情形选择的 行的 index从小到大,如果不用此方法,会造成越界异常。