Solved

Passing a progressbar to a procedure

Posted on 2001-08-04
4
390 Views
Last Modified: 2011-05-16
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
Comment
Question by:DerkEimers
4 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6352153
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
 
LVL 4

Accepted Solution

by:
jsweby earned 10 total points
ID: 6364346
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
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8735435
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question