Delphi ListView1 加载文件列表用法


本文整理自网络,侵删。

 
//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 webservices传base64字串

使用rad studio为安卓内置的java库

Delphi hexstrtobytes

Delphi 字符串左右添加字符

Delphi 单击android上的web浏览器链接以启动Delphi应用程序

Delphi 外壳扩展创建快捷方式和获取快捷方式的目标对象

Delphi共享软件防破解的实用招法

Delphi如何自动重启程序

Delphi datetime,date,time tdatetimepicker

Delphi 调用系统右键菜单

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...