本文整理自网络,侵删。
//OpenDialog1 设置位文件多选 GetFileSize 本站可以搜索到
var i, numExisting, fileSize, fileHandle: Cardinal; item: TListItem; filePath: string;begin if OpenDialog1.Execute then begin numExisting := ListView1.Items.Count; for i := 0 to OpenDialog1.Files.Count - 1 do begin filePath := OpenDialog1.Files[i]; fileHandle := FileOpen(filePath, fmOpenRead); fileSize := GetFileSize(fileHandle, nil); FileClose(fileHandle); item := ListView1.Items.Add; item.Caption := IntToStr(i + numExisting + 1); item.SubItems.Add(filePath); item.SubItems.Append(IntToStr(fileSize)); end; end;
//ListView1 移除选中的文件var i, j, k: Cardinal; removalIndices: array of Cardinal;begin if ListView1.SelCount > 0 then begin j := 0; k := 1; SetLength(removalIndices, ListView1.SelCount); for i := 0 to ListView1.Items.Count - 1 do begin if ListView1.Items[i].Selected then begin removalIndices[j] := i; Inc(j); end else begin ListView1.Items[i].Caption := IntToStr(k); Inc(k); end; end;
for i := Length(removalIndices) - 1 downto 0 do ListView1.Items[removalIndices[i]].Delete; end;
// ListView1 清空
ListView1.Clear;
//
for i := 0 to ListView1.Items.Count - 1 do begin ListView1.Items[i].SubItems[1] end;
//收藏
for i := 1 to ListView1.Items.Count - 1 do begin ListView1.Items[i].SubItems[0] end;
相关阅读 >>
Delphi xe2 - 万一“获取程序自身大小的函数”改进版
更多相关阅读请进入《Delphi》频道 >>