Go Premium for a chance to win a PS4. Enter to Win

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

Passing a progressbar to a procedure

I made a function to copy files from hdd to floppy and want to use a progressbar.

procedure CopyFile(Source, Destionation : string; Progressbar);

But I dunno how to pass the progressbar.. Anyone?
0
DerkEimers
Asked:
DerkEimers
1 Solution
 
intheCommented:
hi,
use shfileoperation  from shellapi:

this is the api that windows/explorer uses and automatically shows the progressbar.

uses ShellAPI;

function CopyAllFiles(sFrom, sTo: string; Protect: boolean): boolean;
var
  F: TShFileOpStruct;
  ResultVal: integer;
  tmp1, tmp2: string;
begin
  FillChar(F, SizeOf(F), #0);
  Screen.Cursor := crHourGlass;
  try
    F.Wnd   := 0;
    F.wFunc := FO_COPY;
    tmp1    := sFrom + #0;
    tmp2    := sTo + #0;
    F.pFrom := PChar(tmp1);
    F.pTo   := PChar(tmp2);
    if Protect then
      F.fFlags := FOF_RENAMEONCOLLISION or FOF_SIMPLEPROGRESS
    else
      F.fFlags := FOF_SIMPLEPROGRESS;
    F.fAnyOperationsAborted := False;
    F.hNameMappings := nil;
    Resultval := ShFileOperation(F);
    Result := (ResultVal = 0);
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
CopyAllFiles('a:\','c:\temp\',true);
end;
0
 
jswebyCommented:
To answer the question, you're almost there:

procedure CopyFile(Source, Destionation : string; Progressbar);

should be

procedure CopyFile(Source, Destionation : string; Progressbar: TProgressBar);

In your CopyFile procedure, referencing Progressbar will affect the progress bar passed into the procedure.

J.



0
 
Russell LibbySoftware Engineer, Advisory Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept jsweby's comment as answer

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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