请教关于Delphi进度条的使用:
我想用delphi实现如下功能:当按下某个按钮运行某个程序时,进度条开始显示进度,当程序运行完时,进度条也显示完。请教各位我该如何实现呢?最好请给出可用代码。非常感谢,切盼中...
参考答案:下面的是拷贝文件时使用进度条的方法.(delphi help例子)
可作参考:
procedure TForm1.Button2Click(Sender: TObject);
const
// On Windows replace, myfile with a pathname such as c:\autoexec.bat
FName = 'MyFile';
var
F: File;
MyData: array[1..2048] of byte;
BytesRead: LongInt;
begin
AssignFile(F, FName);
try
Reset(F);
ProgressBar1.Max := FileSize(F);
if (ProgressBar1.Max > 10) then
ProgressBar1.Step := ProgressBar1.Max div 10
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
end;
finally;
CloseFile(F);
end;
end;