Hello,
Trying to display a progress bar in Delphi 2006 while copying a large file.
My example consists of a VCL Form, Button,OpenDialog,ProgressBar and Timer.
My problem is: The bar will not progress while Copy function is executing.
Here is my code:
Thanks,
Rodney
procedure TForm1.Button1Click(Sender: TObject);
var
FromFile,
ToFile,
Path : string;
begin
if OpenDialog1.Execute then
begin {Create back up copy of DBF file}
Path:= ExtractFilePath(OpenDialog1.FileName);
FromFile:= OpenDialog1.FileName;
ToFile:= Path+'Copy of '+ ExtractFileName(FromFile);
Gauge1.MinValue:= 0;
Gauge1.MaxValue:= 10;
Gauge1.Progress:= Gauge1.MinValue;
Timer1.Enabled:= true;
CopyFile(PChar(FromFile),PChar(ToFile),False);
end;
ShowMessage('Complete');
Timer1.Enabled:= False;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
with Gauge1 do
if (Progress < MaxValue) then Progress:= Progress + 1
else Progress:= 0;
Application.ProcessMessages;
end;