progressbar看看帮助 This example reads bytes from a file in tenths of the size of the file. The ProgressBar displays the status of each 1/10th step as it's read into the buffer. The example assumes a TButton and a TProgressBar control already placed on the form.procedure TForm1.Button1Click(Sender: TObject);const FName = 'c:\autoexec.bat'; 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 // amount to move when StepIt method called 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;
若不是,楼主没必要这么做。一个简单的只有几个Form的程序启动时间相当快,没必要加什么进度条。若需要可以这么做:
响应TApplication的OnIdle消息:
procedure TForm1.ApplicationIdel(Sender:TObject)
begin
Application.OnIdle := nil; ProgressBar.Position := 1;
第1项初始化工作; ProgressBar.Position := 2;
第2项初始化工作;
...
end;
This example reads bytes from a file in tenths of the size of the file. The ProgressBar displays the status of each 1/10th step as it's read into the buffer.
The example assumes a TButton and a TProgressBar control already placed on the form.procedure TForm1.Button1Click(Sender: TObject);const
FName = 'c:\autoexec.bat';
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
// amount to move when StepIt method called
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;
1. 创建一个进度显示窗体(设其类名为TProgressForm),将其改为非自动创建;
2. 修改dpr文件:
program ...;
...
begin
Application.Initialize; ProgressForm := TProgressForm.Create(nil); ProgressForm.进度条.Position := 1;
Application.CreateForm(...);
ProgressForm.进度条.Position := 2;
Application.CreateForm(...);
... FreeAndNil(ProgressForm); Application.Run;
end;
C:\Program Files\Borland\Delphi6\Demos\Db\MastApp工程中。
1. 创建一个进度显示窗体(设其类名为TProgressForm),将其改为非自动创建;
2. 修改dpr文件:
program ...;
...
begin
Application.Initialize; ProgressForm := TProgressForm.Create(nil); ProgressForm.进度条.Position := 1;
Application.CreateForm(...);
ProgressForm.进度条.Position := 2;
Application.CreateForm(...);
... FreeAndNil(ProgressForm); Application.Run;
end;
///////////////////////////////////////////////////////
zhengji(看雨飞) 你说的这种方法我想过。。在form 个数小的地方还行的通
现在如果我有几百个form 的话可能。。
我现在是想。。看有没有什么通用的方法。
重写 CreateForm,调用TApplication的 CreateForm ,同时给出进度显示,OK?这里所要做的只是事先算一下需要创建机个窗口而已。确定是需要改动 Delphi 既有的 Application 对象,比较麻烦,