Delphi 加载大文件显示进度条


本文整理自网络,侵删。

 
procedure TForm1.Button1Click(Sender: TObject);
const
  FName = 'about.txt';  // use a file larger than 2048 bytes to make it interesting.
var
  F: File;
  MyData: array[1..2048] of byte;
  BytesRead: LongInt;
begin
  AssignFile(F, FName);
  try
    Reset(F, 1);
    ProgressBar1.Max := FileSize(F);
    if (ProgressBar1.Max > 10) then
    begin
      // amount to move when StepIt method called
      ProgressBar1.Step := ProgressBar1.Max div 10;
      ProgressBar1.Step := Min(ProgressBar1.Step, 2048);
    end
    else
      ProgressBar1.Step := ProgressBar1.Max;
    while (ProgressBar1.Position < ProgressBar1.Max) do
    begin
      // read one Step size chunk of data to buffer
      BlockRead(F, MyData, ProgressBar1.Step, BytesRead);
      // move the ProgressBar Position using StepIt
      ProgressBar1.StepIt; // move by Step amount
      // Do this or the read will wrap and start over!
      ProgressBar1.Step :=
          Min(ProgressBar1.Step, ProgressBar1.Max - ProgressBar1.Position);

    end;
  finally;
    CloseFile(F);
  end;
end;

相关阅读 >>

Delphi 字符串显示后5位

Delphi 10 seattle的android应用程序中使用参数启动服务

Delphi ip地址转换

Delphi deletefile 删除文件

Delphi读写utf-8、unicode格式文本文件

Delphi richedit根据鼠标位置定位光标的方法

Delphi数值转ip

Delphi 计算运行耗时的方法1

Delphi edit控制字居中,居左,居右

Delphi ttabcontrol控件使用

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



打赏

取消

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

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

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

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

评论

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