form上加上一个ProgressBar1控件
procedure TfrmMain.mycopyfile(sourcef, targetf: string);
var
FromF, ToF: file;
NumRead, NumWritten: Integer;
Buf: array[1..2048] of Char;
n: integer;
begin
AssignFile(FromF, sourcef);
Reset(FromF, 1); { Record size = 1 }
AssignFile(ToF, targetf); { Open output file }
Rewrite(ToF, 1); { Record size = 1 }
n := 0;
sb1.Panels[3].Text := '备份数据进度';
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
ProgressBar1.Position := (sizeof(buf) * n * 100 div FileSize(FromF));
application.ProcessMessages;
//显示进度
BlockWrite(ToF, Buf, NumRead, NumWritten);
inc
;
until (NumRead = 0) or (NumWritten <> NumRead);
sb1.Panels[3].text := '进度';
ProgressBar1.Position := 0;
CloseFile(FromF);
CloseFile(ToF);
end;