[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

Using progressbar to show disk operation.

This question has probably been asked before but here it goes.

How do one go about using a progressbar to show disk operation as in the following:

Copying of files, to show how much of the file has been copied,

0
delbrad
Asked:
delbrad
  • 2
1 Solution
 
WaldekCommented:
You may use SHFileOperation . It show a progress window. If it is no way tell.
0
 
delbradAuthor Commented:
Thanks for the quick response but that was not what I was looking for, I want to be able to use my own dialog with a progressbar...
0
 
WaldekCommented:
OK. If You copy using BlockRead You must read by block. If You know number of block You may update progressbar
0
 
interCommented:
If you copy file from you application, take this. Otherwise this does not help. Also you may want to enhance this. We worked before so no need to demand more points.

Bye friend, (and bye to all the other friends may this piece of code works!-no no I use it several times dont wory!)

Igor

{
  Copies a file from S to D, and if Pr <> nil updates it
}
procedure CopyFileX(Pr : TProgressBar ;SOffset : LongInt; S, D: String);
var
  Src, Dest : TFileStream;
  Ptr  : pointer;
  red  : longint;
begin
 Ptr:= nil;
 Src:= nil;
 Dest:= nil;
 try
  Src := TFileStream.Create(S, fmOpenRead);
  Src.Seek(SOffset, soFromBeginning);
  Dest:= TFileStream.Create(D, fmCreate or fmOpenWrite);
  if Pr <> nil then
  begin
    Pr.Max := Round(Dest.Size/1024);
    Pr.Position := 0;
  end;
  GetMem(Ptr, 32000);
  while Src.Position <> Src.Size do
  begin
    red := Src.Read(Ptr^, 32000);
    Dest.Write(Ptr^, red);
    if Pr <> nil then
      Pr.StepBy(Round(red/1024));
    Application.ProcessMessages;
  end;
 finally
  if Assigned(Ptr) then FreeMem(Ptr, 32000);
  if Assigned(Src) then Src.Free;
  if Assigned(Dest) then Dest.Free;
 end;
end;

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now