我想实现取得listbox中所有文件的总大小,
如果它的个数指定比较好做,但是如果它的个数不确定,
由用户选定后才确定。
设m:=listbox.items.count; n:=listbox.itemindex;
当n从0到m-1时,如何取得总大小呢?

解决方案 »

  1.   

    使用ListBox1.Selected[i]来逐项判断是否被选定,选定的作统计处理
      

  2.   

    var
      i,m: Integer;
      size,sum: Integer;
      f: File of Bytel;
    begin
       sum:= 0;
       for i:= 0 to listbox.items.count-1 do
       begin
         if not listbox.select[i] then break;
         size:= 0;
         try
           AssignFile(f, listbox.items[i]);  //构造Listbox时文件名包括详细路径
           Reset(f);
           size := FileSize(f);
         finally
           CloseFile(f);
         end;
         sum:= sum+ size;
       end;
       showmessage('All Files size in bytes: ' + inttostr(sum));
    end;
      

  3.   

    jan2002(阿吉)  可以了 
    添加文件的大小到一个变量